如何异步引发事件 [英] How to raiseEvent asynchronously

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

问题描述

我一直在找几天没有找到答案,

I have been searching for days without finding an answer,

我有一个作为线程触发的类.该课程将根据发生的事件引发事件.

I have a class that is fired as a thread. This class will raise events depening on what is happening.

我遇到的最大问题是,当我引发该事件时,该事件不会继续,直到正在接收的课程完成处理.

The big problem i have is that when i raise the event it does not continue untill the receving class finish the handling.

我该如何引发一次募集事件并继续执行我的代码?

How can i fire a raiseevent and continue my code?

示例:

example:

Public Class demo
    Public Event OneEvent()

    Sub working()
        'some code
        RaiseEvent OneEvent()
        'some code
    End Sub

End Class

在上面的代码中,我的线程正在工作.并触发该事件,并等待该事件完成.但我希望它在完成之前继续前进.

我认为我必须对invoke或begininvoke做些事情,但我做对了.有人可以帮我吗?

In the above code my thread is working. and fires the event and waits untill this event is done. but i would like it to move along beofore it is done.

I Think i have to do something with invoke or begininvoke but i can't get it right. Can someone help me please?


推荐答案

BeginInvoke是正确的,如果该事件的代码应在UI线程上运行.本质上,Invoke将消息发送到UI的消息泵(同步),而BeginInvoke将消息发布到泵(异步).
考虑使用实现细节的BackgroundWorker.
BeginInvoke is correct if code for the event should run on the UI thread.  Invoke essentially sends a message to the UI's message pump (which is synchronous) and BeginInvoke posts a message to the pump (which is asynchronous).
Consider using the BackgroundWorker, which implements the details.


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

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