并行事件在C#处理 [英] Parallel event handling in C#

查看:122
本文介绍了并行事件在C#处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发具有处理多个事件从外部系统来的模块。
我已经使用第三方类,它提供一些传递参数作为输入和两个作为输出,每一个事件以需要大量的时间来处理一个事件(OnNewMessage)。我想为这些事件在一个平行的方式,以避免阻塞调用者和并行处理多个请求

I’m developing a module that has to handle many events coming from an external system. I’ve to use a third party class providing an event (OnNewMessage) passing some parameters as input and two as output, each event require a bunch of time in order to be processed. I’d like to serve these events in a parallel way, in order to avoid blocking the caller and to process multiple request in parallel.

下面的我的代码示例:

Here an example of my code:

void Init()
{
   provider.OnNewMessage += new OnMessageEventHandler(processEvent);
}

void processEvent(string xml, int …, out string resultXML, out string description)
{
   ...
}

这是做这在C#3.5?

Which is the best approach to do this in C# 3.5?

由于

推荐答案

我会用一个队列来存储事件,然后从线程从bounch消耗该队列线程池。

I would use a queue to store the events, and then consume that queue from a bounch of thread from the thread pool.

这篇关于并行事件在C#处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆