Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lloydjatkinson/61bcb279f9733dffae8d9fa9298fe0eb to your computer and use it in GitHub Desktop.
Save lloydjatkinson/61bcb279f9733dffae8d9fa9298fe0eb to your computer and use it in GitHub Desktop.
internal class Program
{
private readonly static ManualResetEvent _manualResetEvent = new ManualResetEvent(false);
internal static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.CancelKeyPress += HandleExit;
// Application logic here.
_manualResetEvent.WaitOne();
}
internal static void HandleExit(object sender, ConsoleCancelEventArgs eventArguments)
{
Console.WriteLine("Safely exiting.");
Thread.Sleep(3000);
eventArguments.Cancel = true;
_manualResetEvent.Set();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment