Consider a console application that runs some services in a separate thread. All you have to do is wait for the user to press Ctrl + C to close it.
Which of the following is the best way to do this?
static ManualResetEvent _quitEvent = new ManualResetEvent(false); static void Main() { Console.CancelKeyPress += (sender, eArgs) => { _quitEvent.Set(); eArgs.Cancel = true; };
Or this using Thread.Sleep (1):
static bool _quitFlag = false; static void Main() { Console.CancelKeyPress += delegate { _quitFlag = true; };
multithreading c # sleep manualresetevent
intoOrbit Apr 6 '10 at 16:45 2010-04-06 16:45
source share