Add JoinableTaskFactory.DisableProcessing()#1576
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a JoinableTaskFactory.DisableProcessing() API to suppress message pumping (e.g., COM RPC reentrancy via CoWait) during synchronous waits within the ambient JoinableTask, plus tests and samples demonstrating the behavior.
Changes:
- Introduce
JoinableTaskFactory.DisableProcessing()and plumb aDisableProcessingflag throughJoinableTaskand its synchronization context’sWaitoverride. - Add .NET Framework STA tests and a COM-based probe (
CoWaitMainThreadTransition) to validate CoWait penetration vs. blocking behavior. - Update samples/docs wiring (new DisableProcessing sample, SuppressRelevance sample ref update) and bump version.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| version.json | Bumps package version to 18.7. |
| test/Microsoft.VisualStudio.Threading.Tests/NonConcurrentSynchronizationContextTests.cs | Adjusts tuple nullability in an existing test. |
| test/Microsoft.VisualStudio.Threading.Tests/NoMessagePumpSyncContextTests.cs | Adds STA tests validating no-message-pump waits (NETFRAMEWORK only). |
| test/Microsoft.VisualStudio.Threading.Tests/JoinableTaskFactoryTests.cs | Adds tests for DisableProcessing() behavior and nesting. |
| test/Microsoft.VisualStudio.Threading.Tests/CoWaitMainThreadTransition.cs | Adds a COM-based probe to detect whether CoWait/message pumping occurs (NETFRAMEWORK only). |
| test/Microsoft.VisualStudio.Threading.Tests/AsyncCrossProcessMutexTests.cs | Tweaks abandoned-mutex assertions in TryEnterAsync_AbandonedMutex. |
| src/Microsoft.VisualStudio.Threading/Strings.resx | Adds NoAmbientTask resource string for the new API exception. |
| src/Microsoft.VisualStudio.Threading/ReentrantSemaphore.cs | Updates sample code reference for SuppressRelevance. |
| src/Microsoft.VisualStudio.Threading/NoMessagePumpSyncContext.cs | Refines OS/runtime conditional compilation for Windows detection. |
| src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs | Adds DisableProcessing() public API and ProcessingDisabledOperation token. |
| src/Microsoft.VisualStudio.Threading/JoinableTask.cs | Adds internal DisableProcessing flag and sync context propagation. |
| src/Microsoft.VisualStudio.Threading/JoinableTask+JoinableTaskSynchronizationContext.cs | Adds DisableProcessing support and overrides Wait to use WaitForMultipleObjects when enabled. |
| samples/SuppressRelevance.cs | Renames sample type and fixes a spelling error in a comment. |
| samples/Polyfill.cs | Adds NETFRAMEWORK polyfill stub used by samples. |
| samples/DisableProcessing.cs | Adds new sample referenced by the new API docs. |
| .github/copilot-instructions.md | Clarifies namespace expectations for new files vs. test files. |
701e9e7 to
5812af0
Compare
kayle
reviewed
Apr 22, 2026
kayle
reviewed
Apr 22, 2026
kayle
approved these changes
Apr 22, 2026
This method is like the WPF `Dispatcher.DisableProcessing()` method, except that it impacts the `SynchronizationContext` that `JoinableTask` delegates execute within. As part of this, I introduce a test helper class for actually testing the penetrability of sync blocks so we can adequately test this new API. Since this test helper also can apply to `NoMessagePumpSyncContext` testing (which did not exist), I added new tests for that class too.
5812af0 to
c1a7f7c
Compare
3869f31 to
a7d1c6f
Compare
…`JoinableTaskFactory`-derived types
a7d1c6f to
1613479
Compare
…child JoinableTasks
kayle
approved these changes
Apr 23, 2026
This was referenced Jun 23, 2026
Merged
Closed
Merged
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sample use case:
This also enhances the
JoinableTaskFactory.WithPriority(Dispatcher)extension method so that it automatically honors calls toDispatcher.DisableProcessing()to match its behavior.