Hi Peter,
In my opinion, as the problem here seems to be what issues might arise from invoking anasync method in the middle of the navigation sequence, how about invoking theasync operations after the navigation is completed?
The RegionNavigationService provided by Prism to perform navigation request defines a Navigated event that is raised at the end of the navigation sequence. You could take advantage of this event to be notified when the navigation is finished, this means when your view / view model is already created, injected and activated in the region.
For example, you could do something like this to:
// Common synchronous method.publicvoid OnNavigatedTo(NavigationContext context) {// We take any data we require from the navigation context and save it // Then we subscribe to the Navigated event with an async method context.NavigationService.Navigated += OnNavigationCompleted; }
public async void OnNavigationCompleted(...) {// The same NavigationService as before (for example, stored in a private member.) navigationService.Navigated -= OnNavigationCompleted; navigationService = null; Task<IList<Employee>> task = this.employeeService.EmployeLookupListAsync();// Perform some other logic Employees = await task; }
Also, for the opposite case (that is, when using async operations when a view isnavigated from) you can wait for the asynchronous operations to finish using theConfirmNavigationRequest method. You can find more information about this in the following section of the documentation:
I hope you find this useful,
Damian Cherubini
http://blogs.southworks.net/dcherubini