I need to raise an event from a form in a new thread.
(I do not think that the reason for this is relevant, but just in case: I will raise events from code in the form of WndProc sub. If the code that processes the event blocks something in the form [for example, msgbox], then there are all kinds of problems with disconnected contexts and what not. I confirmed that raising events in new threads fixes the problem.)
This is what I am doing now:
Public Event MyEvent() Public Sub RaiseMyEvent() RaiseEvent MyEvent End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Dim t As New Threading.Thread(AddressOf RaiseMyEvent) t.Start() End Sub
Is there a better way?
As far as I understand, events in VB actually consist of delegates in the background. Is there a way to raise events in new threads without creating a subsystem for each? Or is there a more suitable method that I should use?
source share