Me.Invoke in VB.NET doesn't actually "Invoke" - threads stall on Invoke statement
invoke, multithreading, vb.net
Solution
The Invoke method puts a message in the message queue to perform the method call in the main thread. This means that you need a main thread with a message pump. If the main thread is busy, or if you are doing this in an application without a message pump (e.g. a console application), the message will just remain in the queue.
Problem
I've got the following code: ``` Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub SetStatusBarText(ByVal StatusText As String) If Me.InvokeRequired Then Me.Invoke(New SetStatusBarTextDelegate(AddressOf SetStatusBarText), StatusText) Else Me.labelScanningProgress.Text = StatusText End If End Sub ``` The problem is that, when I call the "SetStatusBarText" sub from another thread, InvokeRequired is True (as it should be), but then my threads stall on the Me.Invoke statement - pausing execution shows them all just sitting there, not actually invoking anything. Any thoughts about why the threads seem to be afraid of the Invoke?