Beispiel #1
0
        public void Stop(CancellationToken cancellationToken = default, bool immediate = false)
        {
            _logger.Info(() => "Stopping background task host");

            var options = new ParallelOptions
            {
                CancellationToken = cancellationToken, MaxDegreeOfParallelism = ResolveConcurrency()
            };

            var pendingTasks = _pending.Where(entry => entry.Value.OnHalt != null);

            Parallel.ForEach(pendingTasks, options, async e =>
            {
                // FIXME: halt operation won't have user data in this context
                using var context = ProvisionExecutionContext(cancellationToken, null);

                // ReSharper disable once AccessToDisposedClosure (this is safe: immediately invoked and blocking)
                await e.Value.OnHalt.HaltAsync(context, immediate);
            });

            _pending.Clear();

            _scheduler?.Dispose();
            _scheduler = null;

            _background.Stop(immediate);
            _maintenance.Stop(immediate);
        }
        public void Stop(bool immediate, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation(_localizer.GetString("Stopping operations host"));

            _scheduler?.Dispose();
            _scheduler = null;

            _background?.Stop(immediate);
            _maintenance?.Stop(immediate);
        }