Questions tagged «manualresetevent»


8
如何保持.NET控制台应用程序运行?
考虑一个控制台应用程序,该应用程序在单独的线程中启动某些服务。它所要做的就是等待用户按下Ctrl + C将其关闭。 以下哪一项是更好的方法? static ManualResetEvent _quitEvent = new ManualResetEvent(false); static void Main() { Console.CancelKeyPress += (sender, eArgs) => { _quitEvent.Set(); eArgs.Cancel = true; }; // kick off asynchronous stuff _quitEvent.WaitOne(); // cleanup/shutdown and quit } 或者使用Thread.Sleep(1): static bool _quitFlag = false; static void Main() { Console.CancelKeyPress += delegate { …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.