Run a sub from within a tread?

  • Thread starter Thread starter Justin
  • Start date Start date
J

Justin

I'm a newbie to threads. I can run
"comboProfiles_SelectedIndexChanged(sender, e)" from any normal sub in my
project however if I run this from within a new thread I've started it
doesn't like "sender" or "e". I know sending info from within a thread is
different but what I'm doing should be simple so if someone can help me out
I sure would appreciate it.

Thanks Much,
Justin
 
Justin said:
I'm a newbie to threads. I can run
"comboProfiles_SelectedIndexChanged(sender, e)" from any normal sub in my
project however if I run this from within a new thread I've started it
doesn't like "sender" or "e". I know sending info from within a thread is
different but what I'm doing should be simple so if someone can help me
out

First, I would rethink if calling an event handler is really the best
solution.

Second, don't forget that Windows Forms controls' instance members are not
safe for multithreading.

Third, you can use
'Control.Invoke'/'Control.BeginInvoke'/'Control.InvokeRequired' to call a
method in the context of the main UI thread from within a secondary thread:

Multithreading in Windows Forms-Anwendungen
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=de>
 
Awesome. Thanks Herfried.


Herfried K. Wagner said:
First, I would rethink if calling an event handler is really the best
solution.

Second, don't forget that Windows Forms controls' instance members are not
safe for multithreading.

Third, you can use
'Control.Invoke'/'Control.BeginInvoke'/'Control.InvokeRequired' to call a
method in the context of the main UI thread from within a secondary
thread:

Multithreading in Windows Forms-Anwendungen
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=multithreading&lang=de>
 

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