I have a view + viewmodel which appears as a dialog box. The view has a few combo boxes. In the ViewModel I have an override of OnImportsSatisifed which uses an [Import]ed DataService to populate the ComboBoxes (for example, one box has a
list of all staff members, about 20 names). I also have an override of ActivateView which is passed the parameters needed to initialize the View.
My problem is that OnImportsSatisfied is called first and then ActivateView is called ... but ... the DataService is asynchronous (of course) and does not return prior to ActivateView being called. This means that this first call to ActivateView does
not have access to the reference data. For example, the parameter passed to ActivateView may have a particular staff member who should be selected in the combo box but the items have not been loaded yet.
Does this make sense? Closing the dialog box and then reopening it works just fine because the DataService has returned by this stage and the combo boxes are loaded.
How should I handle this sort of thing - a different action (ActivateView) depends on an asynchronous action (OnImportsSatisfied) being complete?
At the moemnt I have some flags set up that both ActivateView and OnImportsSatisfied check and set to see who is finished first and decide when work should be done. This feels very clunky and I probably have a race condition that I haven't spotted.