Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone.

Ok so I have been told that you cannot run a thread created by another program in VB.net without using an invoke? Is this true? I believe this also helps the thread to become thread safe?! Can anyone explain this or suggest a better way of running this thread?

Thanks,
James
Posted
Comments
Alan N 25-May-11 12:25pm    
I don't think anyone is going to able to answer this as you appear to have mixed up many concepts. Can I suggest you rewrite the question in relation to a specific problem. As a starter we'll need to know about "another program" and "this thread".

1 solution

This is related exclusively to the UI.

You cannot call anything in UI from a non-UI thread. You can use BeginInvoke or Invoke of System.Threading.Dispatcher (both forms and WPF, preferred) or System.Windows.Forms.Control (Forms only, apparently).

See detailed explanation and samples code in my past asnwers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

More links on thread use:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

If you want to do something like that to a general-purpose (non-UI) thread, it needs a special effort. I actually implemented a very similar invocation mechanism.

Please see my Tips/Tricks article here for a full source code, detailed explanation and usage samples:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900