Skip to content

Instantly share code, notes, and snippets.

@bluewalk
Created October 10, 2019 13:01
Show Gist options
  • Select an option

  • Save bluewalk/f6d45e2a9782b902092bc921eb629a74 to your computer and use it in GitHub Desktop.

Select an option

Save bluewalk/f6d45e2a9782b902092bc921eb629a74 to your computer and use it in GitHub Desktop.

Revisions

  1. bluewalk created this gist Oct 10, 2019.
    35 changes: 35 additions & 0 deletions KeepConsoleOpenInDocker.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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();
    }
    }