Exemplo n.º 1
0
 /// <summary>
 /// Starts the given Task when this Task ended successfully.
 /// </summary>
 /// <param name="followingTask">The task to start.</param>
 /// <param name="target">The DispatcherBase to start the following task on.</param>
 /// <returns>This task.</returns>
 public static Task Then(this Task that, Task followingTask, DispatcherBase target)
 {
     that.WhenFailed(() =>
     {
         followingTask.Abort();
     });
     that.WhenSucceeded(() =>
     {
         if (target != null)
         {
             followingTask.Run(target);
         }
         else if (ThreadBase.CurrentThread is TaskWorker)
         {
             followingTask.Run(((TaskWorker)ThreadBase.CurrentThread).TaskDistributor);
         }
         else
         {
             followingTask.Run();
         }
     });
     return(that);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Invokes the given action with the set result of the task when the task succeeded.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <param name="target">The DispatcherBase to perform the action on.</param>
 /// <returns>This task.</returns>
 public static Task <T> OnResult <T>(this Task <T> task, Action <T> action, DispatcherBase actionTarget)
 {
     return(task.WhenSucceeded <T>(t => action(t.Result), actionTarget));
 }
Exemplo n.º 3
0
 /// <summary>
 /// The given Action will be performed when the task succeeds.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task <T> WhenSucceeded <T>(this Task <T> task, Action <Task <T> > action)
 {
     return(task.WhenSucceeded <T>(action, null));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Invokes the given action with the set result of the task when the task succeeded.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <param name="target">The DispatcherBase to perform the action on.</param>
 /// <returns>This task.</returns>
 public static Task OnResult <T>(this Task task, Action <T> action, DispatcherBase target)
 {
     return(task.WhenSucceeded(t => action((T)t.RawResult), target));
 }