Example #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                // 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();

                if (_shutdownWatcher != null)
                {
                    _shutdownWatcher.Dispose();
                }

                if (_context != null)
                {
                    _context.Dispose();
                }

                _disposed = true;
            }
        }
        internal static WebJobsShutdownWatcher Create(CancellationTokenSource cancellationTokenSource)
        {
            WebJobsShutdownWatcher watcher = new WebJobsShutdownWatcher(cancellationTokenSource, ownsCancellationTokenSource: false);

            if (watcher._watcher == null)
            {
                watcher.Dispose();
                return(null);
            }

            return(watcher);
        }
        internal static WebJobsShutdownWatcher Create(CancellationTokenSource cancellationTokenSource)
        {
            WebJobsShutdownWatcher watcher = new WebJobsShutdownWatcher(cancellationTokenSource, ownsCancellationTokenSource: false);

            if (watcher._watcher == null)
            {
                watcher.Dispose();
                return null;
            }

            return watcher;
        }