#296 Keep the process alive long enough to shutdown gracefully.

This commit is contained in:
Chris R 2015-06-19 15:04:42 -07:00
parent 2c43b350b4
commit 98f8bf6fd3
1 changed files with 7 additions and 2 deletions

View File

@ -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<IApplicationShutdown>();
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();
}
}