unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.77k stars 707 forks source link

Updating UI from Background Thread stops working after Navigating to a Page more than once #18182

Open MartinZikmund opened 6 days ago

MartinZikmund commented 6 days ago

Discussed in https://github.com/unoplatform/uno/discussions/18178

Originally posted by **ebondur** September 10, 2024 I am currently trying to update the UI of a page when an NFC read occurs. As monitoring the android device for NFC messages occurs on a background thread, the UI is updated from the background thread as well. When I first navigate to the page, everything works as expected. However, when I navigate away and back to the page, all UI updating stops. Here is the current behavior using a button to simulate NFC reads: https://github.com/user-attachments/assets/e8bd98c2-4a74-4938-b0ea-a655024d47de Expected behavior is that The UI should update every time if the updates originate from the background thread, even if the page has been navigated to more than once. Only way to fix the issue is to close and reopen the app, which is not viable solution. [Sample Repo](https://github.com/ebondur/UnoBackgroundUIUpdateBug) can be found here.
Youssef1313 commented 6 days ago

Shouldn't UI updates be pushed through dispatcher when on background thread rather than updating it from the background thread? Does pushing to dispatcher make any difference?

ebondur commented 6 days ago

Using the dispatcher does not make any difference....

Could this be due to the generated models and data binding?

ebondur commented 6 days ago

Fwiw, I managed to devise a workaround via accessing the bindable model's ICommand for updating the UI. In the sample repo, this is on the Workaround branch.