Control.CheckForIllegalCrossThreadCalls to use Interlocked.Increment/Decrement
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### Background and motivation
Control.CheckForIllegalCrossThreadCalls is Boolean value that is not thread safe.
### API Proposal
Replace with
```csharp
Control.BeginIllegalCrossThreadCall() => Interlocked.Increment(...);
Control.EndIllegalCrossThreadCall() => Interlocked.Decrement(...);
Control.CheckForIllegalCrossThreadCalls => (Interlocked.Read(...) == 0);
### API Usage
```csharp
Control.BeginIllegalCrossThreadCall() ;
try
{
// Get control handle, etc.
nint handle = control.Handle;
}
finally
{
Control.EndIllegalCrossThreadCall() ;
}
```
### Alternative Designs
Control.CheckForIllegalCrossThreadCalls could be [ ThreadStatic ].
### Risks
_No response_
### Will this feature affect UI controls?
Yes.
Will VS Designer need to support the feature? No
What impact will it have on accessibility? No
Will this feature need to be localized or be localizable? No
Contributor guide
Assessment
This issue has not been assessed yet.