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); }
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); }
public static Task WhenSucceeded(this Task task, Action <Task> action, DispatcherBase actiontargetTarget) { Action <Task> perform = delegate(Task t) { if (actiontargetTarget == null) { action(t); } else { actiontargetTarget.Dispatch(delegate { if (t.IsSucceeded) { action(t); } }); } }; return(task.WhenEnded(delegate(Task t) { if (t.IsSucceeded) { perform(t); } }, null)); }
public Task Run(DispatcherBase target) { if (target == null) { return(Run()); } target.Dispatch(this); return(this); }
public static Task WhenEnded(this Task task, Action <Task> action, DispatcherBase target) { task.TaskEnded += delegate { if (target == null) { action(task); } else { target.Dispatch(delegate { action(task); }); } }; return(task); }