-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
MainThread.InvokeOnMainThreadAsync() when called from non-UI thread says "Unable to find main thread" in Windows #18221
Comments
Hi @jonmdev. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version. You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Thanks but I will not bother trying new version or making a repro for this one. I can't use .net 8 due to this bug: Application.Current.Dispatcher.DispatchAsync() works fine and I will keep using it. |
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
now running into this issue, where the debug version of the app works fine, but when building said app it constantly crashes due to these errors. |
This is the workaround I made. Just create this as a static class and use this instead:
I am not sure why or when this bug happens. It is not consistent or easy to trigger. I just tried and couldn't come up with a bug project to reproduce it. Either way the above should fix it. |
Description
I note the thread here from 2 years ago which is locked so I couldn't reply:
#2451
This is still an issue. If you attempt to use
MainThread.InvokeOnMainThreadAsync()
from a non-UI thread in Windows in .NET 7 it replies with an exceptionUnable to find main thread
.I see in that in that thread @mattleibow says "we probably need to remove MainThread from essentials because it make no sense because windows has no root window and there may be multiple threads, each with a window. So which to pick?"
So is it a given this function doesn't work in WIndows and we shouldn't use it? Or is it a bug?
I couldn't tell from the conclusion of that thread: Should this function work or not?
I note using
Application.Current.Dispatcher.DispatchAsync()
otherwise identically does seem to work in Windows. And I tested it in Android/iOS and it seems to work there too. So I presume we should use that instead?If
MainThread.InvokeOnMainThreadAsync()
is not expected to be Windows safe then perhaps it should be removed?Thanks.
Version with bug
7.0.96
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Windows
Did you find any workaround?
Application.Current.Dispatcher.DispatchAsync()
works fine for the same function in at least Windows/Android/iOS.The text was updated successfully, but these errors were encountered: