Skip to content

Instantly share code, notes, and snippets.

@bluewalk
Created October 10, 2019 13:01
Show Gist options
  • Save bluewalk/f6d45e2a9782b902092bc921eb629a74 to your computer and use it in GitHub Desktop.
Save bluewalk/f6d45e2a9782b902092bc921eb629a74 to your computer and use it in GitHub Desktop.
Keep a .NET Core console app open in Docker container
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