public static void ExecuteOnIdleAsync(Action p) { var scheduler = DynamoRevit.RevitDynamoModel.Scheduler; var task = new DelegateBasedAsyncTask(scheduler); task.Initialize(p); scheduler.ScheduleForExecution(task); }
public void AllComplete_ExecutesCallbackWhenAllAreDiscarded() { var run = false; var s = MockMaker.Empty<IScheduler>(); var t1 = new DelegateBasedAsyncTask(s); var t2 = new DelegateBasedAsyncTask(s); var l = new List<AsyncTask>() { t1, t2 }; l.AllComplete((_) => { run = true; }); t1.HandleTaskDiscarded(); t2.HandleTaskDiscarded(); Assert.True(run); }
/// <summary> /// Add a new task to the scheduler to be executed and after that run a /// follow-up task. /// </summary> /// <param name="a">The task to be run in the scheduler</param> /// <param name="h">The follow up handler to be executed</param> private void RunOnSchedulerSync(Action a, AsyncTaskCompletedHandler h) { var task = new DelegateBasedAsyncTask(scheduler, a); task.ThenPost(h, DispatcherSynchronizationContext.Current); scheduler.ScheduleForExecution(task); }
public void AllComplete_ReturnsDisposableThatDisposesAllRegistrations() { var run = false; var s = MockMaker.Empty<IScheduler>(); var t1 = new DelegateBasedAsyncTask(s); var t2 = new DelegateBasedAsyncTask(s); var l = new List<AsyncTask>() { t1, t2 }; l.AllComplete((_) => { run = true; }).Dispose(); t1.HandleTaskCompletion(); t2.HandleTaskDiscarded(); Assert.False(run); }