Skip to content

Add JoinableTaskFactory.DisableProcessing()#1576

Merged
AArnott merged 5 commits into
mainfrom
dev/andarno/disableProcessing
Apr 23, 2026
Merged

Add JoinableTaskFactory.DisableProcessing()#1576
AArnott merged 5 commits into
mainfrom
dev/andarno/disableProcessing

Conversation

@AArnott

@AArnott AArnott commented Apr 22, 2026

Copy link
Copy Markdown
Member

Sample use case:

jtf.Run(
    async delegate
    {
        jtf.DisableProcessing();
        // Code that cannot afford to be interrupted by COM RPC calls during synchronously blocking calls.
    });

This also enhances the JoinableTaskFactory.WithPriority(Dispatcher) extension method so that it automatically honors calls to Dispatcher.DisableProcessing() to match its behavior.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a DisableProcessing flag through JoinableTask and its synchronization context’s Wait override.
  • 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.

Comment thread samples/Polyfill.cs
Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Copilot AI review requested due to automatic review settings April 22, 2026 19:37
@AArnott AArnott force-pushed the dev/andarno/disableProcessing branch from 701e9e7 to 5812af0 Compare April 22, 2026 19:37
Comment thread samples/DisableProcessing.cs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs
Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs Outdated
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.
@AArnott AArnott force-pushed the dev/andarno/disableProcessing branch from 5812af0 to c1a7f7c Compare April 22, 2026 20:12
Copilot AI review requested due to automatic review settings April 22, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Comment thread src/Microsoft.VisualStudio.Threading/JoinableTaskFactory.cs Outdated
@AArnott AArnott force-pushed the dev/andarno/disableProcessing branch from 3869f31 to a7d1c6f Compare April 22, 2026 21:27
@AArnott AArnott force-pushed the dev/andarno/disableProcessing branch from a7d1c6f to 1613479 Compare April 22, 2026 21:29
Copilot AI review requested due to automatic review settings April 23, 2026 14:49
This was referenced Jun 23, 2026
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.

3 participants