Пример #1
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 WhenSucceeded(this Task task, Action <Task> action)
 {
     return(task.WhenEnded(t => { if (t.IsSucceeded)
                                  {
                                      action(t);
                                  }
                           }));
 }
Пример #2
0
 /// <summary>
 /// The given Action will be performed when the task fails.
 /// </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 WhenFailed(this Task task, Action <Task> action, DispatcherBase target)
 {
     return(task.WhenEnded(t => { if (t.IsFailed)
                                  {
                                      action(t);
                                  }
                           }, target));
 }
Пример #3
0
 /// <summary>
 /// The given Action will be performed when the task fails.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task WhenFailed(this Task task, Action action)
 {
     return(task.WhenEnded(t => { if (t.IsFailed)
                                  {
                                      action();
                                  }
                           }));
 }
        /// <summary>
        /// Performs the given Func sequential for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable <Task <TResult> > SequentialForEach <TResult, T>(this IEnumerable <T> that, Func <T, TResult> action, TaskDistributor target)
        {
            var  result   = new List <Task <TResult> >();
            Task lastTask = null;

            foreach (var element in that)
            {
                var tmp  = element;
                var task = Task.Create(() => action(tmp));
                if (lastTask == null)
                {
                    task.Run(target);
                }
                else
                {
                    lastTask.WhenEnded(() => task.Run(target));
                }
                lastTask = task;
                result.Add(task);
            }
            return(result);
        }
Пример #5
0
        /// <summary>
        /// The given Action will be performed when the task succeeds.
        /// </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 WhenSucceeded(this Task task, Action <Task> action, DispatcherBase actiontargetTarget)
        {
            Action <Task> perform = t =>
            {
                if (actiontargetTarget == null)
                {
                    action(t);
                }
                else
                {
                    actiontargetTarget.Dispatch(() => { if (t.IsSucceeded)
                                                        {
                                                            action(t);
                                                        }
                                                });
                }
            };

            return(task.WhenEnded(t => { if (t.IsSucceeded)
                                         {
                                             perform(t);
                                         }
                                  }, null));
        }
Пример #6
0
        /// <summary>
        /// The given Action will be performed when the task succeeds.
        /// </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> WhenSucceeded <T>(this Task <T> task, Action <Task <T> > action, DispatcherBase target)
        {
            Action <Task <T> > perform = t =>
            {
                if (target == null)
                {
                    action(t);
                }
                else
                {
                    target.Dispatch(() => { if (t.IsSucceeded)
                                            {
                                                action(t);
                                            }
                                    });
                }
            };

            return(task.WhenEnded <T>(t => { if (t.IsSucceeded)
                                             {
                                                 perform(t);
                                             }
                                      }, null));
        }
Пример #7
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task WhenEnded(this Task task, Action <Task> action)
 {
     return(task.WhenEnded(t => action(t), null));
 }
Пример #8
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task WhenEnded(this Task task, Action action)
 {
     return(task.WhenEnded(t => action()));
 }
Пример #9
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task <T> WhenEnded <T>(this Task <T> task, Action <Task <T> > action)
 {
     return(task.WhenEnded <T>(action, null));
 }
Пример #10
0
 /// <summary>
 /// The given Action will be performed when the task ends.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <returns>This task.</returns>
 public static Task <T> WhenEnded <T>(this Task <T> task, Action action)
 {
     return(task.WhenEnded <T>(t => action(), null));
 }