Aug 24, 2012 at 12:22 PM
Edited Aug 24, 2012 at 12:23 PM
In our application some modules need to prompt the user to save changes if the user requests to close the module. This is a WPF application using UNITY. We require all calls to
our service layers (WFC) be asynchronice and never block the UI thread.
When closing a module using IConfirmNavigationRequest the module detects if the user has made changes and prompts them to save from within the ConfirmNavigationRequest method.
If user chooses to save, we make the async call to the WCF service, and return "true" for the continuationCallback action in method ConfirmNavigationRequest.
Is this the correct way to do this? The module does save correctly but it also closes the view immediately while the async call is performing the save on a different thread. I'm
just not sure if this is going to give us issues moving forward with memory management.
Aug 24, 2012 at 7:37 PM
Based on my understanding this seems to be a valid approach for achieving this kind of functionality. In my opinion you should be able to avoid that the view closes immediately while the asynchronous call is being performed by calling the
continuationCallback action when the service completes. As far as I know, when working with this kind of services you should be able to pass a callback method which will we called when the execution of the service ends. For example this callback
method could be a lambda expression which ends up calling the continuationCallback(true) method allowing the navigation to continue.
You could find more information about this in the following resources:
On the other hand, depending on the requirements of your scenario you should also consider implementing the
IRegionMemberLifetime interface provided with Prism, in your view / viewmodel. This will allow you to control the lifetime of views within regions by allowing you to specify whether deactivated views are to be removed from
the region or simply marked as deactivated. The IRegionMemberLifetime
interface defines a KeepAlive property, and if this property returns
false, the view will be removed from the region when it is deactivated (in your case when the navigation is confirmed). This is Because the region no longer has a reference to the view, and it then becomes eligible for garbage collection (unless
some other component in your application maintains a reference
I hope you find this useful,