-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
UIElement.Measure not threadsafe in .NET 7+ #8447
Comments
@sra-michaelgold - Can you please share a sample repro if possible. (or a TTD) ? |
Looking at the callstack of your exception, I see that you bind to objects that do not implement |
@pchaurasia14 - I will try to get a repro up and running. @Laniusexcubitor - You raise a good point. Since these are essentially reports, we may be able to set our bindings to OneTime, which avoids this whole issue. I will report back with either a repro or an update on changing the bindings. |
As a late follow up to this, I took @Laniusexcubitor's suggestion and implemented INPC on all the relevant view models (even if their values never changed after construction). I also set Binding Mode to OneTime/OneWay wherever possible and it has resolved the issue in the sense that the Thank you |
Description
It seems a change was introduced as part of the .NET 7 release that makes UIElement.Measure no longer thread-safe.
Our application loads a number of XPS reports (our custom objects that extend ContentControl) in separate dispatcher threads that we manage. Prior to upgrading to .NET 7 we can call Measure on the reports in parallel with no issues. Once upgrading to .NET 7 (same also happens in .NET 8) we start to get the exception below.
I think the problem may have been introduced in this commit:
dotnet/runtime@826896f
where hashtables were changed to dictionaries. Though the hashtable is not necessarily threadsafe, it seems to effectively be acting "more threadsafe" than the dictionary. That said, it's hard to follow this code, so it could be a red-herring.
I can get around the issue by synchronizing the calls to .Measure(), but ideally the behavior in .NET7+ would work the same as .NET 6 (and prior).
Reproduction Steps
Create a number of STA dispatcher threads and load the same XAML based control in all of the threads and call Measure() on the controls
Expected behavior
No exceptions
Actual behavior
Regression?
Yes, this worked fine in .NET6 and broke in .NET7+
Known Workarounds
Synchronize access to Measure()
Impact
Medium - there is a work-around, but it may have some performance impacts
Configuration
.NET7, .NET8
Windows 10 x64
I don't know if it is specific to this config.
Other information
No response
The text was updated successfully, but these errors were encountered: