I am writing a WPF application. One of my view models has bindable property that holds an observable collection:
public ObservableCollection<ItemVm> Items {get; }
There is a long process, I would like to run, that modifies the observable collection, but I don't want to block the UI while its working, so I would like to split the process into a list of tasks and run them one by one. Since each of these tasks modify the collection, these tasks must run on the UI thread. I was hoping to find a way to schedule them on the UI thread in a way the allows it to perform other tasks (animations, responding to the user, etc) and only move on to the next task when the UI thread is not busy.
Having a method running in the UI thread, start another task in the UI thread is something I usually do like this:
task.Start(TaskScheduler.FromCurrentSynchronizationContext());
Except this way I can not enter any priority. I know that I could control the priority using the dispatcher but I would prefer to do it with tasks.