I made a change to my app to load data (using async/await) on background threads while the app opens. Now, after the app has fully loaded, when trying to update a bound property, I'm getting this exception:
A first chance exception of type 'System.NotSupportedException' occurred in PresentationFramework.dll
Additional information: This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread.
This code was working before the async/await changes updated that property in the first place. I tried adding Dispatcher.Invoke() around the code, but I got the same error:
System.Windows.Application.Current.Dispatcher.Invoke(() =>
{
this._customVariableGroups[index] = savedGroup;
});
Since this field was originally updated on a background thread, is that causing problems with updating it from the main thread? Note, in the threads window in Visual Studio, this code is executing on the main thread. I'm not sure what else to do to get this to work.
This is the field:
private ObservableCollection<CustomVariableGroup> _customVariableGroups;