internal static WebJobShutdownWatcher Create(CancellationTokenSource cancellationTokenSource) { var watcher = new WebJobShutdownWatcher(cancellationTokenSource, false); if (watcher._watcher != null) { return(watcher); } watcher.Dispose(); return(null); }
protected virtual void Dispose(bool disposing) { if (!disposing || _disposed) { return; } // Running callers might still be using this cancellation token. // Mark it canceled but don't dispose of the source while the callers are running. // Otherwise, callers would receive ObjectDisposedException when calling token.Register. // For now, rely on finalization to clean up _shutdownTokenSource's wait handle (if allocated). _shutdownTokenSource.Cancel(); _stoppingTokenSource.Dispose(); _shutdownWatcher?.Dispose(); // free event Console.CancelKeyPress -= OnCancelKeyPress; _disposed = true; }