JoinableTaskContext.CreateNoOpContext Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the JoinableTaskContext class that is configured to no-op on calls to SwitchToMainThreadAsync(CancellationToken).
public static Microsoft.VisualStudio.Threading.JoinableTaskContext CreateNoOpContext ();
static member CreateNoOpContext : unit -> Microsoft.VisualStudio.Threading.JoinableTaskContext
Public Shared Function CreateNoOpContext () As JoinableTaskContext
Returns
A new instance of JoinableTaskContext.
Remarks
This method is equivalent to calling the JoinableTaskContext() constructor with the Current property first set to null
. This entry point however will have the same behavior regardless of the value of Current.
The caller's thread will still be captured for use by such properties as MainThread and IsOnMainThread. These properties generally have no effect except as used by application-specific code beyond this library.
This method is useful for creating a JoinableTaskContext in a unit test environment or in a process that does not have a main thread, but which includes code that requires an instance of JoinableTaskContext or JoinableTaskFactory. Such code can receive the instance returned by this method and use it in a normal way but no main thread switches will be honored.
Thread safety concern: Because main thread switches will not be honored, code that requests the main thread as a means of avoiding concurrency may malfunction due to data race conditions.