mui icon indicating copy to clipboard operation
mui copied to clipboard

OnNavigatingFrom wait for async task

Open ikondrasovas opened this issue 9 years ago • 2 comments

Hi,

How can I make OnNavigatingFrom wait for an async operation to complete before actually navigating from and at the same time do not freeze the UI thread?

For example:

public async void OnNavigatingFrom(FirstFloor.ModernUI.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            await TaskEx.Run(() =>
            {
                System.Threading.Thread.Sleep(5000); //replace by my async operation
            });
        }

Although the method does not return until operation is complete, the navigation is performed immediately. How can I hold navigation until the task is complete?

I opened a similar thread here, but no success so far.

Thank you,

ikondrasovas avatar Dec 01 '16 10:12 ikondrasovas

I don't think it's possible the way you're trying, maybe you can hold the navigation showing a dialog window with a processing message/animation and close it when your process is finished.

(I haven't tried it)

heraclesaraujo avatar Dec 01 '16 10:12 heraclesaraujo

What I am doing so far is to cancel the navigation and start an AsyncCommand in the ViewModel.

The ideia is when the command is complete, the VM navigates back using an injected navigation service.

The problem now is that although I managed to implement a navigation service on MUI I still have two separated navigation histories, the one from NavigationService and the other from the ModernFrame, that is used when user clicks on modern links.

How can I unify these histories?

I added a new issue about this matter: https://github.com/firstfloorsoftware/mui/issues/150

ikondrasovas avatar Dec 02 '16 13:12 ikondrasovas