General
- Your model should not return an
ObservableCollectionbecause that collection should be used only if it'sits change notification ability is needed (e.g. with data binding). The methodGetDocumentsshould return anArrayor anIEnumerable. - The methodemethod
InitializeColumnsseems also seems to be GUI related. Consider to movemoving it theto the view model.
Background Processing
If you have to load the documents in the background, I would suggest to useusing BackgroundWorker (for .Net Framework 3.5 and below). But you should use it more like that:
- Pass the model to the
RunWorkerAsyncmethod and use theArgumentproperty to access it. - Do not access view model properties from within the
DoWorkdelegate because that is the code that will be executed in the background. Assign the calculated result to theResultPropertyproperty instead. - Use the RunWorkCompleted
RunWorkCompletedmethod to process the calculated result on the GUI thread.
e.g:
var bw = new BackgroundWorker();
bw.DoWork += (o, e) => e.Result = (e.Argument as Model).GetDocuments();
bw.RunWorkerCompleted += (s, e) => ShippingDocuments = new ObservableCollection((ShippingDocument[])e.Result);
bw.RunWorkerAsync(model);