Skip to content

Control.CheckForIllegalCrossThreadCalls to use Interlocked.Increment/Decrement #13172

Description

@ulfemsoy

Background and motivation

Control.CheckForIllegalCrossThreadCalls is Boolean value that is not thread safe.

API Proposal

Replace with

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

Metadata

Metadata

Assignees

Labels

api-suggestion(1) Early API idea and discussion, it is NOT ready for implementation

Fields

No fields configured for Feature.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions