/// <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, SynchronizationContext.Current); scheduler.ScheduleForExecution(task); }
private void ResetWatch() { // When the node has no input connected, the preview should be empty // Without doing this, the preview would say "null" if (watch.IsPartiallyApplied) { rootWatchViewModel.Children.Clear(); rootWatchViewModel.IsCollection = false; return; } // If the node hasn't been evaluated, no need to update the UI if (!watch.HasRunOnce) { return; } var s = dynamoViewModel.Model.Scheduler; WatchViewModel wvm = null; // prevent data race by running on scheduler var t = new DelegateBasedAsyncTask(s, () => { wvm = GetWatchViewModel(); }); // then update on the ui thread t.ThenPost((_) => { //If wvm is not computed successfully then don't post. if (wvm == null) { return; } // store in temp variable to silence binding var temp = rootWatchViewModel.Children; rootWatchViewModel.Children = null; temp.Clear(); temp.Add(wvm); // rebind rootWatchViewModel.Children = temp; rootWatchViewModel.CountNumberOfItems(); rootWatchViewModel.CountLevels(); rootWatchViewModel.Children[0].IsTopLevel = true; }, syncContext); s.ScheduleForExecution(t); }
private void UpdateColorRange() { var s = dynamoViewModel.Model.Scheduler; // prevent data race by running on scheduler var t = new DelegateBasedAsyncTask(s, () => { colorRange = ComputeColorRange(); }); // then update on the ui thread t.ThenPost((_) => { var bmp = CreateColorRangeBitmap(colorRange); gradientImage.Source = bmp; }, syncContext); s.ScheduleForExecution(t); }