Skip to content
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

Try check the current thread first #5673

Merged
merged 1 commit into from
Mar 30, 2022
Merged

Try check the current thread first #5673

merged 1 commit into from
Mar 30, 2022

Conversation

mattleibow
Copy link
Member

Description of Change

Issues Fixed

Fixes #5671

@mattleibow mattleibow added this to the 6.0.300-rc.1 milestone Mar 30, 2022

if (dispatcher == null)
throw new InvalidOperationException("Unable to find main thread.");

if (!dispatcher.TryEnqueue(DispatcherQueuePriority.Normal, () => action()))
throw new InvalidOperationException("Unable to queue on the main thread.");
}

static DispatcherQueue? TryGetDispatcherQueue() =>
DispatcherQueue.GetForCurrentThread() ??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetForCurrentThread - this is get for current UI/Main thread? is that assumed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets for the current thread. So if you are in the background, it will return null. However, at startup, you are on the thread with a dispatcher. But yeah, no way to get the "main thread" as any thread can be a "main thread" if it has a UI context set up.

@Redth Redth merged commit 48840b8 into main Mar 30, 2022
@Redth Redth deleted the dev/fix-5671 branch March 30, 2022 17:51
@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
@samhouts samhouts added the fixed-in-6.0.300-rc.1 Look for this fix in 6.0.300-rc.1! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-6.0.300-rc.1 Look for this fix in 6.0.300-rc.1!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WinUI] MainThread.BeginInvokeOnMainThread no longer works if fired before a window has been created
3 participants