Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Gets an awaitable whose continuations execute on the synchronization context with which this instance was initialized, so that both deadlocks and reentrancy are mitigated.
Namespace: Microsoft.VisualStudio.Threading
Assembly: Microsoft.VisualStudio.Threading (in Microsoft.VisualStudio.Threading.dll)
Syntax
'Declaration
Public Function SwitchToMainThreadAsync ( _
cancellationToken As CancellationToken _
) As JoinableTaskFactory.MainThreadAwaitable
public JoinableTaskFactory.MainThreadAwaitable SwitchToMainThreadAsync(
CancellationToken cancellationToken
)
public:
JoinableTaskFactory::MainThreadAwaitable SwitchToMainThreadAsync(
CancellationToken cancellationToken
)
member SwitchToMainThreadAsync :
cancellationToken:CancellationToken -> JoinableTaskFactory.MainThreadAwaitable
public function SwitchToMainThreadAsync(
cancellationToken : CancellationToken
) : JoinableTaskFactory.MainThreadAwaitable
Parameters
cancellationToken
Type: System.Threading.CancellationTokenA token whose cancellation immediately schedules the continuationon a threadpool thread.
Return Value
Type: Microsoft.VisualStudio.Threading.JoinableTaskFactory.MainThreadAwaitable
An awaitable.
Examples
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();
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.