I spawn a thread (only one) to do some work and it pretty much takes care of itself not accessing any data outside of the tread except calling callback() to see if the user wants to quit (also sends a status report back to the main thread to display in the GUI).
When the close closes the exe i would like to wake up the thread and have it quit, whats the best way of doing this? The callback already says if the user wants to quit so now the issue is using Thread.Sleep and waking it up prematurely so it can quit instead of having the process live for another few seconds or minutes. This feature would be nice for stop to exit more quickly.
Another approach would be as follows:
Have a
ManualResetEventin your program and callSetwhen you want the thread to finish up and close down. Instead of callingThread.Sleepon your work thread, callevent.WaitOneand pass in aTimeSpanobject. If the event is signalled, your worker thread will wake up before the timeout occurs –WaitOnewill returntrue.