Control.ToString() should call Debugger.NotifyOfCrossThreadDependency()
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
Control.ToString() here calls Dispatcher.Invoke synchronously:
https://github.com/dotnet/wpf/blob/3cae6e13e3f4ba33a4e823e6dc345a3ac27deb92/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Control.cs#L500-L502
When an instance of Control or a derived type is evaluated in the debugger from a background thread this results in a hang since other threads are suspended so the call to Dispatcher never returns.
Consider calling Debugger.NotifyOfCrossThreadDependency: https://referencesource.microsoft.com/#mscorlib/system/diagnostics/debugger.cs,564f13aa1fd18c60
Or even better, think of a simpler ToString() implementation that avoids calling Dispatcher in the first place. I'd even prefer just returning the type name when called from a background thread.
Derived types have the freedom to override ToString() anyway, providing more meaningful information in a safe way. This just covers the default case where derived types should just get a safe default behavior.
Contributor guide
Assessment
This issue has not been assessed yet.