共用方式為


JoinableTaskContext Constructors

Definition

Overloads

JoinableTaskContext()

Initializes a new instance of the JoinableTaskContext class assuming the current thread is the main thread and Current will provide the means to switch to the main thread from another thread.

JoinableTaskContext(Thread, SynchronizationContext)

Initializes a new instance of the JoinableTaskContext class.

JoinableTaskContext()

Initializes a new instance of the JoinableTaskContext class assuming the current thread is the main thread and Current will provide the means to switch to the main thread from another thread.

public:
 JoinableTaskContext();
public:
 JoinableTaskContext();
 JoinableTaskContext();
public JoinableTaskContext ();
Public Sub New ()

Remarks

When Current is null at the time this constructor is invoked, requests to switch to the main thread using SwitchToMainThreadAsync(CancellationToken) will not result in any thread switch. This is appropriate for unit test environments where there is no main thread to switch to or processes which otherwise do not define a main thread. Thread safety concern: When configured without a synchronization context, code that requests the main thread as a means of avoiding concurrency may malfunction due to data race conditions.

Applies to

JoinableTaskContext(Thread, SynchronizationContext)

Initializes a new instance of the JoinableTaskContext class.

public JoinableTaskContext (System.Threading.Thread mainThread = default, System.Threading.SynchronizationContext synchronizationContext = default);
public JoinableTaskContext (System.Threading.Thread? mainThread = default, System.Threading.SynchronizationContext? synchronizationContext = default);
new Microsoft.VisualStudio.Threading.JoinableTaskContext : System.Threading.Thread * System.Threading.SynchronizationContext -> Microsoft.VisualStudio.Threading.JoinableTaskContext
Public Sub New (Optional mainThread As Thread = Nothing, Optional synchronizationContext As SynchronizationContext = Nothing)

Parameters

mainThread
Thread

The thread to switch to in SwitchToMainThreadAsync(CancellationToken). If null, the current thread will be assumed to be the main thread.

synchronizationContext
SynchronizationContext

The synchronization context to use to switch to the main thread.

If null is specified (or the argument is omitted), the current synchronization context will be used. If Current is also null, requests to switch to the main thread using SwitchToMainThreadAsync(CancellationToken) will not result in any thread switch. This is appropriate for unit test environments where there is no main thread to switch to or processes which otherwise do not define a main thread. Thread safety concern: When configured without a synchronization context, code that requests the main thread as a means of avoiding concurrency may malfunction due to data race conditions.

Applies to