Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Event Handlers processed Asynchronously?

In VB .NET, when you call RaiseEvent X(), is the function that handles the event X processed asynchronously or synchronously. I was under the impression that RaiseEvent and the processing of the event were Synchronous unless created explictly on another thread. I've been told otherwise though.

like image 759
Josh Smeaton Avatar asked Jun 16 '09 00:06

Josh Smeaton


2 Answers

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.

like image 73
Andrew Hare Avatar answered Sep 25 '22 14:09

Andrew Hare


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

like image 21
Josh Smeaton Avatar answered Sep 22 '22 14:09

Josh Smeaton