Skip to content

The commands attached to gestures in Android MAUI project will not run from MainThread #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dalux-era opened this issue Sep 12, 2023 · 5 comments

Comments

@dalux-era
Copy link

dalux-era commented Sep 12, 2023

Hi,

It seems that when using an MR layout in MAUI Android app, when we attach a command to a gesture, the handler is called outside of Main thread. iOS works as expected. A simple test can be done in the sample project. In CustomEventArgsViewModel.cs add a thread check in OnDown method

        if (MainThread.IsMainThread)
        {
	        /// Handling the Action in main thread
        }
	AddText(DownUpInfo("Down", e));

Can we get more information on whether it is a know issue?

@MichaelRumpler
Copy link
Owner

Yes, unfortunately this is a known issue.

In the very early days somebody deleted an element in the event handler of that element. When my handler continued after the users code, an exception was raised because the element has already been disposed. So I raised all event handlers on a new thread.
In hindsight that was a mistake. I should've just told the user not to delete the element in the handler. But eight years later I cannot easily revert this. I would probably break the old code from others.

@dalux-era
Copy link
Author

I see, understandable. Was wondering about this, because it seems that in the Xamarin version of MR.Gestures it still works on the Main thread :)

@MichaelRumpler
Copy link
Owner

AFAIK the code is the same. I'll have a look at it.

@MichaelRumpler
Copy link
Owner

Sorry, I still have troubles getting .NET8 RC1 running.
I'll make sure to run all handlers on the UI thread, but I don't have the time today anymore and I'm on vacation for the next two weeks and also don't want to release right before it.

@MichaelRumpler
Copy link
Owner

I released version 4.0.0 now. This version is for .NET7 and 8.

All the event handlers / commands on Android, Tapped and DoubleTapped on all platforms were previously run from a background thread. They now run on the UI thread.

It did not matter in Xamarin.Forms because many things there could also be changed from a BG thread. MAUI seems to be less forgiving.

Version 4.0.0 DOES NOT include Xamarin.Forms anymore. It is now for MAUI only. If you still need it in XF, stay at v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants