Skip to content

Instantly share code, notes, and snippets.

@alexander-williamson
Created September 18, 2016 11:09
Show Gist options
  • Save alexander-williamson/7e50a24bba89aa3d6c8e77208f844f63 to your computer and use it in GitHub Desktop.
Save alexander-williamson/7e50a24bba89aa3d6c8e77208f844f63 to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
namespace Alexw.RunningConsoleApp
{
public class Program
{
static readonly ManualResetEvent QuitEvent = new ManualResetEvent(false);
static void Main(string[] args)
{
Console.CancelKeyPress += (sender, eArgs) =>
{
QuitEvent.Set();
eArgs.Cancel = true;
};
// your code here
// ...
QuitEvent.WaitOne();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment