Though a robust implement needs state machine and sync between threads, I found AutoRestEvent extremely helpful, especially in this case, where a signal between two threads required.
The document at MSDN appears very tricky to people who have little background of multithreading. Here is my example of how to play around with AutoRestEvent, which is used in my Simulator.
In the thread that you need to listen to another thread, you can simply add code like this
I declare _ShouldContinue as:
public readonly AutoResetEvent _ShouldContinue = new AutoResetEvent(false);
The false in construction indicates the initial state.
Then in the thread which you need to send the signal, just add the following code:
However, even with the help of AutoResetEvent, thread safe can still be a problem, especially dealing with WPF application. For instance, in order not to block the UI, I created three threads just for updating and listening the UI. Thus, I highly recommend you guys read some articles about multithreading before trying AutoResetEvent.