.NET WinForms: suspend code until mouse move or keyboard press
In .NET WinForms I want to display message in a s开发者_StackOverflow中文版tatus bar and suspend the program execution until user moves mouse or presses keyboard. How can I do that?
Put your program into a separate thread, suspend the thread with
System.Threading.Thread.CurrentThread.Suspend()
and restart it from another thread, which is listening to the mouse/keyboard-events.
Edit:
Ok. Thread suspension is evil and not necessary here, as the Program-Thread itself enters a Suspended - better a Sleeping or Waiting state. So just wait (sleep-cycle, WaitHandle - some semaphore, whatever) for the Interface-Thread to allow the Program-Thread to progress.
精彩评论