Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created June 20, 2021 13:20
Show Gist options
  • Save PatrickKalkman/088d0ca1ca786bbd24537cfe8a076b77 to your computer and use it in GitHub Desktop.
Save PatrickKalkman/088d0ca1ca786bbd24537cfe8a076b77 to your computer and use it in GitHub Desktop.
Handling SIGINT & SIGTERM
class Program
{
static async Task Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{
Console.WriteLine("Received SIGTERM");
};
Console.CancelKeyPress += (_, _) =>
{
Console.WriteLine("Received SIGINT");
};
var counter = 0;
var max = args.Length != 0 ? Convert.ToInt32(args[0]) : -1;
while (max == -1 || counter < max)
{
Console.WriteLine($"Counter: {++counter}");
await Task.Delay(1000);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment