diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 6004d8e50f..2ef0635d6f 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Hosting public void Main(string[] args) { - // Allow the location of the ini file to be specfied via a --config command line arg + // Allow the location of the ini file to be specified via a --config command line arg var tempBuilder = new ConfigurationBuilder().AddCommandLine(args); var tempConfig = tempBuilder.Build(); var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile; @@ -39,7 +39,12 @@ namespace Microsoft.AspNet.Hosting { Console.WriteLine("Started"); var appShutdownService = host.ApplicationServices.GetRequiredService(); - Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); }; + Console.CancelKeyPress += (sender, eventArgs) => + { + appShutdownService.RequestShutdown(); + // Don't terminate the process immediately, wait for the Main thread to exit gracefully. + eventArgs.Cancel = true; + }; appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); } }