Language

JoinableTaskFactory.DisableProcessing Method

Definition

Prevents filtered message pumps from running during synchronous waits for the ambient JoinableTask.

public Microsoft.VisualStudio.Threading.JoinableTaskFactory.ProcessingDisabledOperation DisableProcessing();
member this.DisableProcessing : unit -> Microsoft.VisualStudio.Threading.JoinableTaskFactory.ProcessingDisabledOperation
Public Function DisableProcessing () As JoinableTaskFactory.ProcessingDisabledOperation

Returns

A value that may be disposed of when the need to suppress synchronous wait message pumps is ended. Alternatively it may be discarded if the rest of the JoinableTask is intended to have processing disabled.

Exceptions

Thrown when called outside the context of a JoinableTask.

Examples

Here is a simple, common usage of this method:

Following are more examples of how it might be used:

Remarks

During a yielding await within a JoinableTask, no message pump ever runs regardless of whether this method is called, except for the internal one that lets in only relevant work. When user code runs within the JoinableTask delegate or its callees that ends up requiring a synchronous block of the main thread (e.g. synchronous I/O or lock contention), this wait is typically implemented by calling Wait(IntPtr[], Boolean, Int32) on Current. The default implementation of this method allows for certain interruptions (e.g. COM RPC calls), which may avoid deadlocks in certain situations.

Calling this method will replace the default implementation of Wait(IntPtr[], Boolean, Int32) with one that will not allow such interruptions while that JoinableTask is active and in control of Current. As this method may be called multiple times, this effect remains on the target JoinableTask until all DisableProcessing() invocations' return values are disposed (in any order). The effect only applies to the direct JoinableTask. It does not affect any of its children or parents.

Disabling processing has no effect on non-Windows operating systems.

Disposing the resulting value will revert to the default behavior. Callers need not ever dispose of this value if the intent is to disable processing for the remainder of that JoinableTask's execution.

Applies to