Dispost CancellationTokenSource in WebHostExtensions (#23969)

This commit is contained in:
Kahbazi 2020-07-16 19:46:39 +04:30 committed by GitHub
parent cee763b189
commit cf77999a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -50,6 +50,7 @@ namespace Microsoft.AspNetCore.Hosting
public static void Run(this Microsoft.AspNetCore.Hosting.IWebHost host) { }
[System.Diagnostics.DebuggerStepThroughAttribute]
public static System.Threading.Tasks.Task RunAsync(this Microsoft.AspNetCore.Hosting.IWebHost host, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) { throw null; }
[System.Diagnostics.DebuggerStepThroughAttribute]
public static System.Threading.Tasks.Task StopAsync(this Microsoft.AspNetCore.Hosting.IWebHost host, System.TimeSpan timeout) { throw null; }
public static void WaitForShutdown(this Microsoft.AspNetCore.Hosting.IWebHost host) { }
[System.Diagnostics.DebuggerStepThroughAttribute]

View File

@ -19,9 +19,10 @@ namespace Microsoft.AspNetCore.Hosting
/// <param name="timeout">The timeout for stopping gracefully. Once expired the
/// server may terminate any remaining active connections.</param>
/// <returns>A <see cref="Task"/> that completes when the <see cref="IWebHost"/> stops.</returns>
public static Task StopAsync(this IWebHost host, TimeSpan timeout)
public static async Task StopAsync(this IWebHost host, TimeSpan timeout)
{
return host.StopAsync(new CancellationTokenSource(timeout).Token);
using var cts = new CancellationTokenSource(timeout);
await host.StopAsync(cts.Token);
}
/// <summary>