Created
May 10, 2013 13:16
-
-
Save mayvazyan/5554325 to your computer and use it in GitHub Desktop.
Stop your console app the nice way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static readonly AutoResetEvent AutoResetEvent = new AutoResetEvent(false); | |
static void Main(string[] args) | |
{ | |
Console.CancelKeyPress += OnCancelKeyPress; | |
//TODO: do work here | |
AutoResetEvent.WaitOne(); | |
//TODO: shutdown here | |
} | |
private static void OnCancelKeyPress(object sender, ConsoleCancelEventArgs e) | |
{ | |
e.Cancel = true; | |
AutoResetEvent.Set(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment