Search code examples
xamarinasync-awaitthread-safetymvvmcross

Is it okay to call "Navigate()" without awaiting it?


I have a question about the MVVMCross async Navigate() call. If one were to to not "await" the Navigate() call, could there be adverse effects? The awaits were removed in our app to solve an issue were the MVVM command was keeping a button pressed when going back in the navigation, removing the await on Navigate calls solved this, but may have introduced some threading issues.

Navigate in ViewModel with await

await Navigate<MainMenuViewModel>();

Navigate in ViewModel Without await

Navigate<MainMenuViewModel>();

Solution

  • As a general async/await rule, you should always await asynchronous operations. Not awaiting could cause things to execute out of the expected order or locking up the UI thread.

    In this case, it's going to be your call to decide if the risk is worth it. This seems more of a band-aid than a solution to your problem though.