Example #1
0
        public static MvCancelTask Run(Action <CancellationToken> act)
        {
            var task = new MvCancelTask();
            var ct   = task.CancelTokenSource.Token;

            task.Task = Task.Factory.StartNew(() =>
            {
                act(ct);
            }, ct);

            return(task);
        }
Example #2
0
        public static MvCancelTask RunLoop(Func <bool> funcIsContinue, int delay_ms = 0)
        {
            var task = new MvCancelTask();
            var ct   = task.CancelTokenSource.Token;

            task.Task = Task.Factory.StartNew(() =>
            {
                while (!ct.IsCancellationRequested)
                {
                    ct.ThrowIfCancellationRequested();
                    if (!funcIsContinue())
                    {
                        break;
                    }
                    if (delay_ms > 0)
                    {
                        Thread.Sleep(delay_ms);
                    }
                }
            }, ct);

            return(task);
        }