コード例 #1
0
        public void Push(ActionRun <T> item)
        {
            ActionQueue.Enqueue(item);

            if (RunTask.Status == TaskStatus.Created)
            {
                RunTask.Start();
                RunTask.ContinueWith(task =>
                {
                    var ae = task.Exception;
                }, TaskContinuationOptions.OnlyOnFaulted);
            }
            else if (RunTask.Status == TaskStatus.RanToCompletion)
            {
                RunTask.Dispose();
                RunTask = Task.Factory.StartNew(Run);
            }
            else if (RunTask.Status == TaskStatus.Faulted)
            {
                CheckError();

                RunTask.Dispose();
                RunTask = Task.Factory.StartNew(Run);
            }
        }
コード例 #2
0
        public async Task StopAsync()
        {
            if (!Running)
            {
                return;
            }

            CancellationSource.Cancel();
            await RunTask;

            CancellationSource.Dispose();
            CancellationSource = null;
            RunTask.Dispose();
            RunTask = null;
        }