This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
WebHost.Run() completes before ApplicationStopping #812
Closed
Description
When using applicationLifetime.ApplicationStopping.Register(HandleStopping);
the program exits host.Run();
before that handler has completed also the documentation (IntelliSense) says Shutdown will block until this event completes.
This also means that ApplicationStopped will be executed before ApplicationStopping has completed.
Also it should be noted that ApplicationStopping is not executed on the main thread (while ApplicationStopped is) and that you should not use async
for those handler as that will cause the methods to be completed.
This is ASP.NET 1.0.0 on Windows 10 using Kestrel (1.0.0).
Startup.cs
public void Configure(IApplicationLifetime applicationLifetime)
{
applicationLifetime.ApplicationStopping.Register(HandleStopping);
applicationLifetime.ApplicationStopped.Register(HandleStopped);
}
private void HandleStopped()
{
System.Threading.Thread.Sleep(30000);
// WebHost.Run() will not end until this method completes, running it in the main thread
}
private void HandleStopping()
{
System.Threading.Thread.Sleep(30000);
// WebHost.Run() will end even while this method is still working, it will even run HandleStopped before this completed. It run on a worker thread.
}