Beispiel #1
0
        public static FuncTask Run(CancellableFunc doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null)
        {
            var task = new FuncTask(doThis, cancellationToken, scheduler);

            task.Start();
            return(task);
        }
Beispiel #2
0
        internal static FuncTask BuildContinuation(Task antecedent, CancellableFunc doThis, CancellationToken cancellationToken, TaskScheduler scheduler = null)
        {
            var continuation = new FuncTask(doThis, cancellationToken, scheduler);

            continuation.SetStatusToUnstartedContinuation();
            TaskContinuationManager.RegisterContinuation(antecedent, continuation);
            return(continuation);
        }
Beispiel #3
0
 /// <summary>
 /// Creates an unstarted Task
 /// </summary>
 /// <param name="doThis"></param>
 /// <param name="cancellationToken"></param>
 /// <param name="scheduler"></param>
 internal FuncTask(CancellableFunc doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null)
     : base(cancellationToken, scheduler)
 {
     if (doThis == null)
     {
         throw new ArgumentNullException("doThis");
     }
     _work = doThis;
 }
Beispiel #4
0
 /// <summary>
 /// Creates an unstarted Task
 /// </summary>
 /// <param name="doThis"></param>
 /// <param name="scheduler"></param>
 internal FuncTask(Func doThis, TaskScheduler scheduler = null)
     : base(CancellationToken.None, scheduler)
 {
     if (doThis == null)
     {
         throw new ArgumentNullException("doThis");
     }
     _work = token => doThis();
 }
Beispiel #5
0
 public static FuncTask New(CancellableFunc doThis, CancellationToken cancellationToken = null, TaskScheduler scheduler = null)
 {
     return(new FuncTask(doThis, cancellationToken, scheduler));
 }
Beispiel #6
0
 protected override void ExecuteUserWork(CancellationToken cancellationToken)
 {
     _result = _work(cancellationToken);
     _work   = null;
 }