You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
usingSystem;usingSystem.Threading;usingSystem.Threading.Tasks;namespaceCtrlCExit{classProgram{staticintMain(string[]args){vardone=newManualResetEventSlim(false);vartoken=newCancellationTokenSource().Token;using(varcts=CancellationTokenSource.CreateLinkedTokenSource(token)){AttachCtrlcSigtermShutdown(cts,done,shutdownMessage:"Cancel key press received, attempting to exit gracefully.");try{Console.WriteLine("Waiting for Ctrl+C to be pressed...");cts.Token.WaitHandle.WaitOne();}finally{done.Set();}}Console.WriteLine("Exited gracefully.");return1337;}privatestaticvoidAttachCtrlcSigtermShutdown(CancellationTokenSourcects,ManualResetEventSlimresetEvent,stringshutdownMessage){voidShutdown(){if(!cts.IsCancellationRequested){if(!string.IsNullOrEmpty(shutdownMessage)){Console.WriteLine(shutdownMessage);}try{cts.Cancel();}catch(ObjectDisposedException){}}// Wait on the given reset eventresetEvent.Wait();};AppDomain.CurrentDomain.ProcessExit+=(sender,eventArgs)=>Shutdown();Console.CancelKeyPress+=(sender,eventArgs)=>{Shutdown();// Don't terminate the process immediately, wait for the Main thread to exit gracefully.eventArgs.Cancel=true;};}}}
The problem is that dotnet run process itself is being terminated by Ctrl+C and exiting. It does not repro if you run the repro directly without the intermediate process, like dotnet bin\Debug\netcoreapp3.0\repro.dll.
Repro:
dotnet new console
Program.cs
dotnet run
We expect in the below repo for the exit code to be
1337
Built a repro that's inspired by ASP.NET's hosting bits here: https://github.com/aspnet/Hosting/blob/88d33cd665736e9c73298d24901c9dc99607d414/src/Microsoft.AspNetCore.Hosting/WebHostExtensions.cs#L134-L162
Repro:
/cc @halter73 @Tratcher
The text was updated successfully, but these errors were encountered: