Пример #1
0
        /// <summary>
        /// Start new
        /// </summary>
        /// <param name="delay"></param>
        /// <param name="action"></param>
        /// <param name="scheduler"></param>
        /// <returns></returns>
        public static CancellableTask StartNew(TimeSpan delay, Action action = null, TaskScheduler scheduler = null)
        {
            var task = new CancellableTask(action);

            task.Start(delay, scheduler);
            return(task);
        }
Пример #2
0
        /// <summary>
        /// Start new
        /// </summary>
        /// <param name="action"></param>
        /// <param name="delay"></param>
        /// <param name="scheduler"></param>
        /// <returns></returns>
        public static CancellableTask StartNew(Action <CancellationToken> action, TimeSpan?delay = null, TaskScheduler scheduler = null)
        {
            var ts    = new CancellationTokenSource();
            var token = ts.Token;
            var task  = new CancellableTask(() => action(token), token)
            {
                TokenSource = ts
            };

            task.Start(delay ?? TimeSpan.Zero, scheduler);
            return(task);
        }
Пример #3
0
        CancellableTask Prepare()
        {
            LastStart = DateTime.Now;
            var task = CancellableTask.Init(GetAction());

            task
            .OnFaulted(ex => { })
            .OnFullfilled(() =>
            {
                LastComplete = DateTime.Now;
                Interlocked.Increment(ref _count);
            })
            .ContinueWith(t => { Interlocked.CompareExchange(ref _task, null, task); });
            return(task);
        }