Skip to content

Instantly share code, notes, and snippets.

@dterracino
Forked from dkudelko/ConsoleAppMainAsync.cs
Created March 30, 2017 20:44
Show Gist options
  • Save dterracino/e2421cc4efe179fe5ce811af036d27b6 to your computer and use it in GitHub Desktop.
Save dterracino/e2421cc4efe179fe5ce811af036d27b6 to your computer and use it in GitHub Desktop.
async console applicatiion main
class Program
{
static void Main(string[] args)
{
CancellationTokenSource cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
cts.Cancel();
};
MainAsync(args, cts.Token).Wait();
}
static async Task MainAsync(string[] args, CancellationToken token)
{
//todo paste your asnc code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment