I have a thread running in the background. How do i send it messages from my main thread? The only msg i need to send is 'go'/'wakeup'
+1
A:
If you are talking about waking up a sleeping thread - Thread.Suspend()(wait) - Thread.Resume()(go/wake up)
Svetlozar Angelov
2009-08-26 14:40:31
+3
A:
If your thread is doing nothing till you want it to start, then why start it until you want it to go?
If you are looking to run your background thread, then pause/wait for some event, and then continue, a simple method is to use the EventWaitHandle
family of classes.
A simple example (taken from this question). Both threads should have access to the following:
private ManualResetEvent _workerWait = new ManualResetEvent(false);
Then, in your worker thread:
_workerWait.WaitOne();
Now, it will block until your main thread calls:
_workerWait.Set()
For a more complete discussion of your options and some examples, see: http://www.albahari.com/threading/
Nader Shirazie
2009-08-26 14:45:36