Relaxin wrote:
> How do you handle the cross-thread issues if you don't have a UI?
You need a synchronization point. You can't hijack a random thread and
have it pay attention to you; it needs to wait explicitly at some point
so that you can communicate with it.
Apps with UIs have a synchronization point for the main thread in the
form of the message loop. The message loop waits for messages. Other
threads can communicate with it by sending a message. Control.Invoke
works by doing this.
For apps without UIs, you need to set up the synchronization point
yourself. You can do that by implementing a message loop, or a
producer-consumer queue (Google that - there's a trivial textbook
implementation possible using monitors, often one of the first things
taught in college courses when threading is first discussed), or other
methods of cross-thread communication. For example, the main thread
could block until a background thread wakes it up, using e.g.
ManualResetEvent or monitors (Monitor.Wait, Monitor.Pulse, etc.).
-- Barry
--
http://barrkel.blogspot.com/