You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 1, 2024. It is now read-only.
Due to the changes in #12761, Brushes are now tied to a specific Dispatcher.
So, when using the predefined Brushes, all the windows will subscribe to change events on the same brush instance. Then, when that brush uses its Dispatcher to notify these windows, all (but one) will be accessed from the wrong thread, causing exceptions.
There isn't really a workaround (aside for not using the predefined brushes).
Fix
The quick fix is to mark all these predefined brushes as [ThreadStatic].
Although this works, there is still a minor performance penalty because every time a predefined brush is used, its Parent changes, and all the other Views that also use that brush get a notification which (probably) trigger a larger UI update than necessary.
An alternative would be to not set the Parent for these predefined brushes, but I'm not sure if that would have another unexpected impact somewhere else...
The text was updated successfully, but these errors were encountered:
Description
Due to the changes in #12761, Brushes are now tied to a specific Dispatcher.
So, when using the predefined Brushes, all the windows will subscribe to change events on the same brush instance. Then, when that brush uses its Dispatcher to notify these windows, all (but one) will be accessed from the wrong thread, causing exceptions.
Steps to Reproduce
layout.Background = Brush.Gray;
(here)Expected Behavior
Each window should be displayed with their gray background.
Actual Behavior
On UWP, trying to open many secondary windows throw the exception:
I haven't tried on other platforms, but any of them that use many dispatchers will have the same issue.
Basic Information
Workaround
There isn't really a workaround (aside for not using the predefined brushes).
Fix
The quick fix is to mark all these predefined brushes as
[ThreadStatic]
.Although this works, there is still a minor performance penalty because every time a predefined brush is used, its Parent changes, and all the other Views that also use that brush get a notification which (probably) trigger a larger UI update than necessary.
An alternative would be to not set the Parent for these predefined brushes, but I'm not sure if that would have another unexpected impact somewhere else...
The text was updated successfully, but these errors were encountered: