Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: IPartImportsSatisfiedNotification - INavigationAware

$
0
0

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;
}
Then, when the navigation is finished, this method will be raised and the subscribedasync method would be executed. As at this point the navigation is completed, I believe you should be able to perform anyasync operations you want without needing to worry about how them could impact in the navigation sequence:

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


Viewing all articles
Browse latest Browse all 1878

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>