Invoke the main thread

  • Thread starter Thread starter S Shulman
  • Start date Start date
S

S Shulman

Hi

I am looking for a method that allows calling a method that will be executed
by the main application thread bu will be called from any thread that I
create manually.
(I think that technically it is similar to sending a message to the
program)

I tried the Invoke method but it seem to work from the calling thread

Thank you,
Shmuel Shulman
 
You will want to have a delegate function or event handler in your main
application. The function will need to use MyBase.Invoke or .BeginInvoke,
telling the main application to execute the statement. The function you
invoke should be a seperate function. Here is an example of how your main
application should handle the delegate call from the seperate thread(s) -

Private Delegate Sub MyHandlerDelegate()
Private MyDelegate As MyHandlerDelegate = AddressOf _Handler
Private Sub Handler()
MyBase.Invoke(MyDelegate)
End Sub
Private Sub _Handler()
'THIS IS NOW EXECUTED BY THE MAIN THREAD
End Sub

Hope that helps,
Kevin M. Schreiner
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top