Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

Commit

Permalink
Remove Hosting's shutdown handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Ruhnau committed May 8, 2015
1 parent ad93dd7 commit 19fc9fb
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/Microsoft.AspNet.Hosting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,33 +32,14 @@ public void Main(string[] args)
config.AddCommandLine(args);

var host = new WebHostBuilder(_serviceProvider, config).Build();
var serverShutdown = host.Start();
var loggerFactory = host.ApplicationServices.GetRequiredService<ILoggerFactory>();
var appShutdownService = host.ApplicationServices.GetRequiredService<IApplicationShutdown>();
var shutdownHandle = new ManualResetEvent(false);

appShutdownService.ShutdownRequested.Register(() =>
{
try
{
serverShutdown.Dispose();
}
catch (Exception ex)
{
var logger = loggerFactory.CreateLogger<Program>();
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<IApplicationShutdown>();
#if !DNXCORE50 // TODO: Remove the if once .NET Core has a release with CancelKeyPress
Console.CancelKeyPress += delegate { appShutdownService.RequestShutdown(); };
#endif
appShutdownService.ShutdownRequested.WaitHandle.WaitOne();
}
}
}
}

0 comments on commit 19fc9fb

Please sign in to comment.