I have the canonical code to self host an asp.net mvc application, inside a task:
Task hostingtask = Task.Factory.StartNew(() =>
{
Console.WriteLine("hosting ffoqsi");
IWebHost host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}, canceltoken);
When I cancel this task, an ObjectDisposedException throws. How can I gracefully shut down the host?