Created
May 25, 2018 09:20
-
-
Save jaykang920/acb8c529321c51ccfdd1912e00f08c0b to your computer and use it in GitHub Desktop.
.NET Core: handling signals in console app
This file contains hidden or 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
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