Reputation:
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'
Upvotes: 1
Views: 255
Reputation: 10776
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/
Upvotes: 3
Reputation: 21660
If you are talking about waking up a sleeping thread - Thread.Suspend()(wait) - Thread.Resume()(go/wake up)
Upvotes: 1