Esempio n. 1
0
 public new Task <T> Run(DispatcherBase target)
 {
     base.Run(target);
     return(this);
 }
Esempio n. 2
0
 public static Task Await(this Task that, Task taskToWaitFor, DispatcherBase target)
 {
     taskToWaitFor.Then(that, target);
     return(that);
 }
Esempio n. 3
0
        public static IEnumerable <Task> WhenSucceeded(this IEnumerable <Task> that, Action action, DispatcherBase target)
        {
            int    remaining = that.Count();
            object syncRoot  = new object();

            foreach (Task item in that)
            {
                item.WhenSucceeded((Action) delegate
                {
                    lock (syncRoot)
                    {
                        remaining--;
                        if (remaining == 0)
                        {
                            if (target == null)
                            {
                                action();
                            }
                            else
                            {
                                target.Dispatch(delegate
                                {
                                    action();
                                });
                            }
                        }
                    }
                });
            }
            return(that);
        }
Esempio n. 4
0
 public static Task <T> WhenEnded <T>(this Task <T> task, Action <Task <T> > action, DispatcherBase target)
 {
     task.TaskEnded += delegate
     {
         if (target == null)
         {
             action(task);
         }
         else
         {
             target.Dispatch(delegate
             {
                 action(task);
             });
         }
     };
     return(task);
 }
Esempio n. 5
0
 public static Task <T> WhenFailed <T>(this Task <T> task, Action <Task <T> > action, DispatcherBase target)
 {
     return(task.WhenEnded(delegate(Task <T> t)
     {
         if (t.IsFailed)
         {
             action(t);
         }
     }, target));
 }
Esempio n. 6
0
        public static IEnumerable <Task> Then(this IEnumerable <Task> that, Task followingTask, DispatcherBase target)
        {
            int    remaining = that.Count();
            object syncRoot  = new object();

            foreach (Task item in that)
            {
                item.WhenFailed((Action) delegate
                {
                    if (!followingTask.ShouldAbort)
                    {
                        followingTask.Abort();
                    }
                });
                item.WhenSucceeded((Action) delegate
                {
                    if (!followingTask.ShouldAbort)
                    {
                        lock (syncRoot)
                        {
                            remaining--;
                            if (remaining == 0)
                            {
                                if (target != null)
                                {
                                    followingTask.Run(target);
                                }
                                else if (ThreadBase.CurrentThread is TaskWorker)
                                {
                                    followingTask.Run(((TaskWorker)ThreadBase.CurrentThread).TaskDistributor);
                                }
                                else
                                {
                                    followingTask.Run();
                                }
                            }
                        }
                    }
                });
            }
            return(that);
        }
Esempio n. 7
0
        public static Task <T> WhenSucceeded <T>(this Task <T> task, Action <Task <T> > action, DispatcherBase target)
        {
            Action <Task <T> > perform = delegate(Task <T> t)
            {
                if (target == null)
                {
                    action(t);
                }
                else
                {
                    target.Dispatch(delegate
                    {
                        if (t.IsSucceeded)
                        {
                            action(t);
                        }
                    });
                }
            };

            return(task.WhenEnded(delegate(Task <T> t)
            {
                if (t.IsSucceeded)
                {
                    perform(t);
                }
            }, null));
        }
Esempio n. 8
0
        public static IEnumerable <Task> WhenFailed(this IEnumerable <Task> that, Action action, DispatcherBase target)
        {
            bool   hasFailed = false;
            object syncRoot  = new object();

            foreach (Task item in that)
            {
                item.WhenFailed((Action) delegate
                {
                    lock (syncRoot)
                    {
                        if (!hasFailed)
                        {
                            hasFailed = true;
                            if (target == null)
                            {
                                action();
                            }
                            else
                            {
                                target.Dispatch(delegate
                                {
                                    action();
                                });
                            }
                        }
                    }
                });
            }
            return(that);
        }