lepoco / wpfui

WPF UI provides the Fluent experience in your known and loved WPF framework. Intuitive design, themes, navigation and new immersive controls. All natively and effortlessly.
https://wpfui.lepo.co
MIT License
7.04k stars 667 forks source link

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

Open DanClarkLexacom opened 2 months ago

DanClarkLexacom commented 2 months ago

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 ApplyDefaultWindowBordermethod of the ClientBordercontrol. 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

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

nabeelio commented 2 months ago

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