Created
June 20, 2021 13:20
-
-
Save PatrickKalkman/088d0ca1ca786bbd24537cfe8a076b77 to your computer and use it in GitHub Desktop.
Handling SIGINT & SIGTERM
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
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