public void Dispose() { _logger?.Shutdown(); _applicationLifetime.StopApplication(); (_hostingServiceProvider as IDisposable)?.Dispose(); (_applicationServices as IDisposable)?.Dispose(); _applicationLifetime.NotifyStopped(); }
public async Task StopAsync(CancellationToken cancellationToken = default) { if (_stopped) { return; } _stopped = true; _logger?.Shutdown(); var timeoutToken = new CancellationTokenSource(Options.ShutdownTimeout).Token; if (!cancellationToken.CanBeCanceled) { cancellationToken = timeoutToken; } else { cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutToken).Token; } // Fire IApplicationLifetime.Stopping _applicationLifetime?.StopApplication(); if (Server != null) { await Server.StopAsync(cancellationToken).ConfigureAwait(false); } // Fire the IHostedService.Stop if (_hostedServiceExecutor != null) { await _hostedServiceExecutor.StopAsync(cancellationToken).ConfigureAwait(false); } // Fire IApplicationLifetime.Stopped _applicationLifetime?.NotifyStopped(); HostingEventSource.Log.HostStop(); }