Пример #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 void RunUntil(Func <bool> operation)
        {
            var task = new RunTask(operation, IntervalSpeed);

            var inactive = _tasks.Where(t => !t.Running).ToList();

            foreach (var t in inactive)
            {
                _tasks.Remove(t);
            }

            _tasks.Add(task);

            task.Start();
        }