There can be many different scenarios of inter-thread synchronization and passing the data. One of the most widely used patterns is using data queues, in particular, blocking queues; the blocking enables synchronization of the thread expecting data with the availability of the data supplied form other thread(s). On interesting variant of it is using delegate instances, so one thread can pass the whole method with all required parameters (importantly, including "this") to be executed on another thread.
This creates a mechanism similar to the UI thread invocation mechanism (implemented for
System.Windows.Forms
and WPF with
System.Windows.Forms.Control.Invoke (BeginInvoke)
or
System.Windows.Threading.Dispatcher
). But — attention! — such invocation is only available for UI threads through respective UI libraries; for the arbitrary threads, the similar mechanism can be created by a developer, which I demonstrate in my article referenced below.
For further detail, please see my article complete with full source code and usage samples:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[
^].
See also the alternative solution to this article which is applicable to .NET Framework 4.0 and later.
—SA