JoinableTaskFactory::SwitchToMainThreadAsync Method (CancellationToken)
Visual Studio 2015
Gets an awaitable whose continuations execute on the synchronization context with which this instance was initialized, so that both deadlocks and reentrancy are mitigated.
Assembly: Microsoft.VisualStudio.Threading (in Microsoft.VisualStudio.Threading.dll)
public:
JoinableTaskFactory::MainThreadAwaitable SwitchToMainThreadAsync(
CancellationToken cancellationToken = null
)
Parameters
- cancellationToken
-
Type:
System.Threading::CancellationToken
A token whose cancellation immediately schedules the continuationon a threadpool thread.
Return Value
Type: Microsoft.VisualStudio.Threading::JoinableTaskFactory::MainThreadAwaitableAn awaitable.
private async Task SomeOperationAsync() { // on the caller's thread. await DoAsync(); // Now switch to a threadpool thread explicitly. await TaskScheduler.Default; Now switch to the Main thread to talk to some STA object. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); STAService.DoSomething(); }
Show: