docker container exits immediately even with Console.ReadLine() in a .NET Core console application

后端 未结 9 1622
一个人的身影
一个人的身影 2020-12-09 15:43

I am trying to run a .NET Core 1.0.0 console application inside a docker container.
When I run dotnet run command from inside the Demo folder on my machin

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-09 16:08

    I am not sure why Console.ReadLine(); doesn't block the main thread when running a .NET Core console app in a detached docker container, but the best solution is to register a ConsoleCancelEventHandler with the Console.CancelKeyPress event.

    Then you can instead block the main thread with a type of Threading WaitHandle and signal the release of the main thread when Console.CancelKeyPress is fired.

    A good example code can be found here: https://gist.github.com/kuznero/73acdadd8328383ea7d5

提交回复
热议问题