Beispiel #1
0
        public Task Create(BackgroundServerContext context, CancellationToken token)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(Task.Factory.StartNew(() =>
            {
                var workerContext = new BackgroundWorkerContext(context.Console);

                while (!token.IsCancellationRequested)
                {
                    BackgroundWorkerContinuation continuation = _worker.Work(workerContext.Increment(), token);

                    TimeSpan waitTime = continuation.WaitTime.GetValueOrDefault();

                    if (waitTime <= TimeSpan.Zero)
                    {
                        break;
                    }

                    token.WaitHandle.WaitOne(waitTime);
                }
            }, token, TaskCreationOptions.LongRunning, _scheduler));
        }