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

Switching theme from a different thread is raising an exception on Windows 10 #1053

Open
DanClarkLexacom opened this issue Apr 15, 2024 · 1 comment
Assignees
Labels
bug Something isn't working themes Topic is related to managing themes

Comments

@DanClarkLexacom
Copy link

DanClarkLexacom commented Apr 15, 2024

Describe the bug

If you attempt to call ApplicationThemeManager from a different thread a InvalidOperationException is raised detailing that "The calling thread cannot access this object because a different thread owns it.". This exception appears within the ApplyDefaultWindowBorder method of the ClientBorder control. This appears to be isolated to Windows 10 only, because of the operating version check before hand.

There is no guarantee the the ThemeChanged event was raised on the thread, so I only can think that we should be doing a thread safety check and ensuring that we are on the UI thread before updating the UI.

To Reproduce

  • Assume that you are running on a variant of Windows 10.
  • Access and call ApplicationThemeManager.Apply from a different thread other than the UI thread.

Expected behavior

It should be possible to switch theme from a different thread, ensuring that there were thread safety checks done at the place of applying the UI changes.

Screenshots

image

OS version

Windows 10 21H2

.NET version

.net 8.0

WPF-UI NuGet version

3.0.4

Additional context

No response

@DanClarkLexacom DanClarkLexacom added the bug Something isn't working label Apr 15, 2024
@nabeelio
Copy link

nabeelio commented Apr 15, 2024

I use the Dispatcher to make sure it's being run on the main thread

@pomianowski pomianowski self-assigned this Apr 17, 2024
@pomianowski pomianowski added the themes Topic is related to managing themes label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working themes Topic is related to managing themes
Projects
None yet
Development

No branches or pull requests

3 participants