Created
October 10, 2019 13:01
-
-
Save bluewalk/f6d45e2a9782b902092bc921eb629a74 to your computer and use it in GitHub Desktop.
Keep a .NET Core console app open in Docker container
This file contains 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 | |
{ | |
// AutoResetEvent to signal when to exit the application. | |
private static readonly AutoResetEvent WaitHandle = new AutoResetEvent(false); | |
static async Task Main(string[] args) | |
{ | |
var version = FileVersionInfo.GetVersionInfo(typeof(Program).Assembly.Location).ProductVersion; | |
Console.WriteLine($"[APP] version {version}"); | |
Console.WriteLine("[GITHUB_LINK]\n"); | |
var logic = new Logic(); | |
// Fire and forget | |
Task.Run(async () => | |
{ | |
await logic.Start(); | |
WaitHandle.WaitOne(); | |
}); | |
// Handle Control+C or Control+Break | |
Console.CancelKeyPress += async (o, e) => | |
{ | |
Console.WriteLine("Exit"); | |
await logic.Stop(); | |
// Allow the manin thread to continue and exit... | |
WaitHandle.Set(); | |
}; | |
// Wait | |
WaitHandle.WaitOne(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment