如何引发异步事件 [英] How to raise async events

查看:88
本文介绍了如何引发异步事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我正在使用框架1.1处理ac #project。

由于它是一个控制台应用程序,因此没有使用任何窗体。

我正在尝试实现事件驱动的类,只想提高

事件并继续工作(如火和忘记 - 不要等待

客户端的事件处理程序完成。)


我已经浏览了很多关于互联网和MSDN的文章和大多数关于代表(或BackGroundWorker)的b $ b在2.0中我无法使用。
使用。)所有其他解决方案都是针对Windows窗体的类异步

事件以某种方式。


我对一个解决方案感兴趣,它允许两个没有从
继承的类继承自Control类并引发事件并工作以收集异步

fashion 。


我真的很感激,如果有人可以帮我这个。


谢谢,


Nad

Hello,

I am working on a c# project using framework 1.1.
Since its a console application,no windows forms are being used.
I am trying to implement event driven classes that just want to raise
the event and continue working( like fire and forget - do not wait for
the event handler in client to finish.)

I have gone through alot of the articles on internet and MSDN and most
talk about delegates (or BackGroundWorker in 2.0 which I cannot
use.) all the other solutions out there are for classes raisng async
events for windows forms in one way or the other.

I am interested in a solution that allows two classes that do not
inherit from Control class and raise events and work togather in async
fashion.

I will really appreciate if some one can help me with this.

Thanks,

Nad

推荐答案

您可以使用System.Threading.Thread类在

中启动另一个方法新线程。你可以使用

a代表从这个线程正常引发一个事件。


nadeem _... @ yahoo.com写道:
You could use System.Threading.Thread class to start another method in
a new thread. You can raise an event as normal from this thread using
a delegate.

nadeem_...@yahoo.com wrote:

您好,


我正在使用框架1.1处理ac #project。

由于它是一个控制台应用程序,没有窗口表格正在使用。

我正在尝试实现事件驱动的课程,只想提高事件并继续工作(如火和忘记 - 不要等待

客户端的事件处理程序完成。)


谈论代表(或2.0中的BackGroundWorker,我不能使用.b $ b使用。)所有其他解决方案都适用于以某种方式触发async

事件的窗体或者其他。


我对一个解决方案很感兴趣,它允许两个没有从
继承的类继承自Control类并引发事件和工作togather in async

时尚。


我真的很感激,如果有人可以帮我这个。


谢谢,


Nad
Hello,

I am working on a c# project using framework 1.1.
Since its a console application,no windows forms are being used.
I am trying to implement event driven classes that just want to raise
the event and continue working( like fire and forget - do not wait for
the event handler in client to finish.)

I have gone through alot of the articles on internet and MSDN and most
talk about delegates (or BackGroundWorker in 2.0 which I cannot
use.) all the other solutions out there are for classes raisng async
events for windows forms in one way or the other.

I am interested in a solution that allows two classes that do not
inherit from Control class and raise events and work togather in async
fashion.

I will really appreciate if some one can help me with this.

Thanks,

Nad




-

Ignacio Machin
http://www.laceupsolutions.com

手机&仓库解决方案。

< na ******** @ yahoo.com写信息

新闻:44 *********** *********************** @ i12g2000 prf.googlegroups.com ...
Hi,
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<na********@yahoo.comwrote in message
news:44**********************************@i12g2000 prf.googlegroups.com...

您好,
Hello,


>

我感兴趣的解决方案允许两个类没有

继承自Control类并引发事件并以异步方式收集

fashion。
>
I am interested in a solution that allows two classes that do not
inherit from Control class and raise events and work togather in async
fashion.



IIRC在MSDN杂志上有一篇关于在控制台应用程序中使用

事件的文章。我记得它是这个号码的最后一篇文章之一。

这个号码的首页与C#和LINQ有关。所以很容易找到


IIRC there were an article a time ago in MSDN magazine about using events in
a console app. I do remember it was one of the last article in the number.
The front page fo the number was related to C# and LINQ. So it will be easy
to find.


Nad,


在这种情况下,改为只需调用委托,您将需要

获取调用列表,然后在调用列表的每个项目中调用BeginInvoke。这将导致事件从线程池中的线程触发。


当然,这意味着您的订阅者必须知道事实

他们订阅的事件是在另一个线程上。


Juval Lowy创建了一个有趣的小课程,名为EventsHelper

这将为你做这件事:

http://www.idesign.net/idesign/Deskt...19&down​​load=98


你可以找到有关EventsHelper的更多信息:

http://www.idesign.net/idesign/Deskt...dex=5&tabid=11

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


< na ******** @ yahoo.com写信息

新闻:44 ************ ********************** @ i12g2000 prf.googlegroups.com ...
Nad,

In this case, instead of just invoking the delegate, you will want to
get the invocation list and then call BeginInvoke on each of the items in
the invocation list. This will cause the event to be fired on a thread from
the thread pool.

Of course, this means that your subscribers have to be aware of the fact
that the events they subscribe to are on another thread.

Juval Lowy has created an interesting little class called EventsHelper
which will do this for you:

http://www.idesign.net/idesign/Deskt...19&download=98

You can find more information about EventsHelper here:

http://www.idesign.net/idesign/Deskt...dex=5&tabid=11
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<na********@yahoo.comwrote in message
news:44**********************************@i12g2000 prf.googlegroups.com...

您好,


我正在使用框架1.1处理ac #project。

由于它是一个控制台应用程序,因此没有使用任何窗体。

我正在尝试实现事件驱动的类,只想提高事件并继续工作(如火和忘记 - 不要等待

事件处理程序客户完成。)


我已经浏览了很多关于互联网和MSDN的文章和大多数关于代表的讨论(或者我在2.0版本中的BackGroundWorker)

使用。)所有其他解决方案都适用于以某种方式升级async

事件的窗体。


我对一个解决方案感兴趣,该解决方案允许两个没有从
继承的类继承自Control类并引发事件并且在async中工作

时尚。


如果有人能帮助我,我将非常感激。


谢谢,


Nad
Hello,

I am working on a c# project using framework 1.1.
Since its a console application,no windows forms are being used.
I am trying to implement event driven classes that just want to raise
the event and continue working( like fire and forget - do not wait for
the event handler in client to finish.)

I have gone through alot of the articles on internet and MSDN and most
talk about delegates (or BackGroundWorker in 2.0 which I cannot
use.) all the other solutions out there are for classes raisng async
events for windows forms in one way or the other.

I am interested in a solution that allows two classes that do not
inherit from Control class and raise events and work togather in async
fashion.

I will really appreciate if some one can help me with this.

Thanks,

Nad



这篇关于如何引发异步事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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