-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added InvokeOnMainThreadAsync to consolidate GoToAsync calls #15366
Added InvokeOnMainThreadAsync to consolidate GoToAsync calls #15366
Conversation
@PureWeen any thoughts about this one? |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@MaxFelinger do you have a stack trace of your crash? |
@PureWeen My bad it's not an exception that gets thrown, the navigation just won't be executed. I've adjusted the description of this PR. To make things simple for reproduction purposes, someone could use this sample:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@jfversluis Thanks for the additional information. Reproducing this issue: Invoke an async method from OnResume and inside this async method invoke GoToAsync. |
If you change that initial |
@PureWeen yes, when I exchange PS: The posted code is just a sample. The real code that we use in our project does async stuff (load from SecureStorage and a few more things) first and navigates afterwards. Sure we can surround the navigation call by |
Now that we're so close to the sunsetting of Xamarin.Forms unfortunately we won't be able to take this in anymore, we're really sorry about that. Nevertheless, thank you so much for your time and effort that you have put into this PR. Please have a look at the evolution of Xamarin.Forms, .NET MAUI. A lot of development has been going on there. Hopefully this issue was already fixed in that codebase. If not, feel free to port this over to there. Again, thank you so much for being a contributor and Xamarin.Forms user! |
Description of Change
Two of three GoToAsync calls were already wrapped by InvokeOnMainThreadAsync. We had a navigation issue because the third GoToAsync call in ShellNavigationManager is not surrounded by InvokeOnMainThreadAsync.
I do realise that this is a temporary fix and there should be a better fix. Nevertheless this consolidation is better than keeping it broken.
Issues Resolved
Fixes a navigation call that won't be executed otherwise.
We had this issue in the OnResume method. A specific scenario could be that the user has moved the app into the background while being at an important process step. The app could be terminated while it's in the background. To let the user proceed from where he has left off, we added a "ReentryService" that allows the user to jump to an important point where he left off. The ReentryService basically loads some stuff from SecureStorage (asynchronously) and invoked GoToAsync at its end.
I think we also had this issue when we used PushNotification, but I cannot remember the full scenario.
Platforms Affected
Testing Procedure
I'm not sure how to test this case properly. I hope one of you reviewers knows how to test it.