From cee0a48ed5a7811f75a15c2ad810773b3e5587ac Mon Sep 17 00:00:00 2001 From: Kai Ruhnau Date: Thu, 7 May 2015 11:25:57 +0200 Subject: [PATCH] Remove Hosting's shutdown handling --- src/Microsoft.AspNet.Hosting/Program.cs | 34 ++++--------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Program.cs b/src/Microsoft.AspNet.Hosting/Program.cs index 11718b64..55117e00 100644 --- a/src/Microsoft.AspNet.Hosting/Program.cs +++ b/src/Microsoft.AspNet.Hosting/Program.cs @@ -3,12 +3,9 @@ using System; using System.IO; -using System.Threading; -using System.Threading.Tasks; using Microsoft.AspNet.Hosting.Internal; using Microsoft.Framework.ConfigurationModel; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.Logging; using Microsoft.Framework.Runtime; namespace Microsoft.AspNet.Hosting @@ -35,33 +32,12 @@ public void Main(string[] args) config.AddCommandLine(args); var host = new WebHostBuilder(_serviceProvider, config).Build(); - var serverShutdown = host.Start(); - var loggerFactory = host.ApplicationServices.GetRequiredService(); - var appShutdownService = host.ApplicationServices.GetRequiredService(); - var shutdownHandle = new ManualResetEvent(false); - - appShutdownService.ShutdownRequested.Register(() => - { - try - { - serverShutdown.Dispose(); - } - catch (Exception ex) - { - var logger = loggerFactory.CreateLogger(); - logger.LogError("Dispose threw an exception.", ex); - } - shutdownHandle.Set(); - }); - - var ignored = Task.Run(() => + using (host.Start()) { - Console.WriteLine("Started"); - Console.ReadLine(); - appShutdownService.RequestShutdown(); - }); - - shutdownHandle.WaitOne(); + var appShutdownService = host.ApplicationServices.GetRequiredService(); + Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); }; + appShutdownService.ShutdownRequested.WaitHandle.WaitOne(); + } } } }