How to return to original thread

  • Thread starter Thread starter Bob Jacobs
  • Start date Start date
B

Bob Jacobs

Is there a way to explicitly tell .NET to return back to
the original calling thread? I am doing asynchronous
threading and I am trying to figure out if I can (within
the callback after the .EndInvoke) explicitly tell .NET to
go back to the thread from where I called the .BeginInvoke.

Thanks,
Bob
 
Is there a way to explicitly tell .NET to return back to
the original calling thread? I am doing asynchronous
threading and I am trying to figure out if I can (within
the callback after the .EndInvoke) explicitly tell .NET to
go back to the thread from where I called the .BeginInvoke.

Thanks,
Bob

Bob,

If this is a GUI app, then yes - there is a way, sort of :) You can do
something similar to this:

' sub in a form, this is air code - and so syntax may be a little off...
Private Sub AsyncCallback(ByVal ar As IAsyncResult)
' call your end invoke

If Me.InvokeRequired Then
Me.Invoke (New AsyncCallbackDelegate(Me.AsyncCallback), ar)
Else
' Do stuff now that you're back on the ui thread
End If
End Sub
 
Thanks for your answer Tom. I didn't find any property
similar to "me.InvokeRequired" I guess i can pass in the
threadID and compare those, but is there already a system
property on the form that i can use?
 
Thanks for your answer Tom. I didn't find any property
similar to "me.InvokeRequired" I guess i can pass in the
threadID and compare those, but is there already a system
property on the form that i can use?


InvokeRequired is a property of the Control class and a member of the
form. I am assuming a GUI here. Other then using the GUI, I can't
really think of a way to go back to another thread.
 
Back
Top