Skip to content

Instantly share code, notes, and snippets.

@jaykang920
Created May 25, 2018 09:20
Show Gist options
  • Save jaykang920/acb8c529321c51ccfdd1912e00f08c0b to your computer and use it in GitHub Desktop.
Save jaykang920/acb8c529321c51ccfdd1912e00f08c0b to your computer and use it in GitHub Desktop.
.NET Core: handling signals in console app
using System;
// Tested on .NET Core 2.1
class Program
{
static void Main(string[] args)
{
Console.CancelKeyPress += OnSigInt;
AppDomain.CurrentDomain.ProcessExit += OnSigTerm;
// ...
}
// SIGINT signal handler
static void OnSigInt(object sender, ConsoleCancelEventArgs e)
{
// On separate thread
}
// SIGTERM signal handler
static void OnSigTerm(object sender, EventArgs e)
{
// On separate thread
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment