Are Event Handlers processed Asynchronously?

两盒软妹~` 提交于 2019-12-05 10:10:50

Events are raised synchronously by default. Since MulticastDelegates are designed to support asynchronous invocation it is possible to invoke the delegates in an event's invocation list asynchronously but this is not the default behavior.

I just did some testing also...

Public Sub MyHandler() Handles Complete
    MsgBox("My Handler - Beginning 5 second sleep")
    Threading.Thread.Sleep(5000)
    MsgBox("My Handler - Awoken")
End Sub


Public Sub SomeFunction()
    MsgBox("Some function - Raising Event")
    RaiseEvent Complete()
    MsgBox("Some function - After Event")
End Sub

Output:
Some function - Raising Event
My Handler - Beginning 5 second sleep
My Handler - Awoken
Some function - After Event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!