开发者

.NET WinForms: suspend code until mouse move or keyboard press

开发者 https://www.devze.com 2022-12-20 08:13 出处:网络
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 in

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消