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