We have an application built according to the MVVM pattern. At various times we kick off tasks to go to a database to retrieve data, we then populate an ObservableCollection to which a WPF control is bound with that data.
We are a little confused, when we populate the ObservableCollection we are doing so on the task thread, not the UI thread, yet the UI is still updated/behaving correctly. We were expecting an error and to have to change the code to populate the collection on the UI thread.
Is this a dangerous scenario and should we populate on the UI thread anyway?
Code to get data:
Task.Factory.StartNew(() =>
UiDataProvider.RefreshForwardContractReport(fcrIdField.Value)
)
.ContinueWith(task => {
if (task.Result.OperationSuccess)
{
// This updates the ObseravableCollection, should it be run on UI thread??
RefreshReport(task.Result.OperationResult);
}
});