Skip to content

Add JoinableTaskContext.CreateNoOpContext() method - #1345

Merged
Andrew Arnott (AArnott) merged 1 commit into
microsoft:mainfrom
AArnott:jtcCtor
Aug 13, 2024
Merged

Add JoinableTaskContext.CreateNoOpContext() method#1345
Andrew Arnott (AArnott) merged 1 commit into
microsoft:mainfrom
AArnott:jtcCtor

Conversation

@AArnott

Copy link
Copy Markdown
Member

The JoinableTaskContext constructor unfortunately has a poor design where folks passing in null for the SynchronizationContext may mistakenly believe that they're getting a no-op instance when they aren't, if SynchronizationContext.Current != null.

In this change, I add a method that definitely does what they expect.

I also add an analyzer and a code fix provider to help identify code that was likely written with the incorrect expectation to help them switch to the new method which matches their expectation, or suppress the warning with a more clear syntax.

The `JoinableTaskContext` constructor unfortunately has a poor design where folks passing in `null` for the `SynchronizationContext` may mistakenly believe that they're getting a no-op instance when they aren't, if `SynchronizationContext.Current != null`.

In this change, I add a method that *definitely* does what they expect.

I also add an analyzer and a code fix provider to help identify code that was likely written with the incorrect expectation to help them switch to the new method which matches their expectation, or suppress the warning with a more clear syntax.
@AArnott
Andrew Arnott (AArnott) merged commit cc929f4 into microsoft:main Aug 13, 2024
@AArnott
Andrew Arnott (AArnott) deleted the jtcCtor branch August 13, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants