예제 #1
0
        /// <summary>
        /// Starts the given Task when the tasks ended successfully.
        /// </summary>
        /// <param name="that">The that.</param>
        /// <param name="followingTask">The task to start.</param>
        /// <param name="target">The DispatcherBase to start the following task on.</param>
        /// <returns>
        /// The tasks.
        /// </returns>
        public static IEnumerable <CustomTask> Then(this IEnumerable <CustomTask> that, CustomTask followingTask,
                                                    CustomTaskDispatcherBase target)
        {
            var remaining = that.Count();
            var syncRoot  = new object();

            foreach (var task in that)
            {
                task.WhenFailed(() =>
                {
                    if (followingTask.ShouldAbort)
                    {
                        return;
                    }
                    followingTask.Abort();
                });
                task.WhenSucceeded(() =>
                {
                    if (followingTask.ShouldAbort)
                    {
                        return;
                    }

                    lock (syncRoot)
                    {
                        remaining--;
                        if (remaining != 0)
                        {
                            return;
                        }

                        if (target != null)
                        {
                            followingTask.Run(target);
                        }
                        else if (CustomThread.CurrentThread is TaskWorker)
                        {
                            followingTask.Run(((TaskWorker)CustomThread.CurrentThread).TaskDistributor);
                        }
                        else
                        {
                            followingTask.Run();
                        }
                    }
                });
            }
            return(that);
        }
예제 #2
0
 /// <summary>
 /// Starts the given Task when this Task ended successfully.
 /// </summary>
 /// <param name="that">The that.</param>
 /// <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 CustomTask Then(this CustomTask that, CustomTask followingTask, CustomTaskDispatcherBase target)
 {
     that.WhenFailed(followingTask.Abort);
     that.WhenSucceeded(() =>
     {
         if (target != null)
         {
             followingTask.Run(target);
         }
         else if (CustomThread.CurrentThread is TaskWorker)
         {
             followingTask.Run(((TaskWorker)CustomThread.CurrentThread).TaskDistributor);
         }
         else
         {
             followingTask.Run();
         }
     });
     return(that);
 }
예제 #3
0
 public DirectoryCopyAction CopyAsync()
 {
     _task = CustomTask.Create <DirectoryCopyAction>(Copy);
     _task.Run();
     return(this);
 }