JoinableTaskFactory.SwitchToMainThreadAsync 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
오버로드
| Name | Description |
|---|---|
| SwitchToMainThreadAsync(CancellationToken) |
교착 상태와 재진입을 모두 완화하는 방식으로 주 스레드에서 연속이 실행되는 대기 대기자를 가져옵니다. |
| SwitchToMainThreadAsync(Boolean, CancellationToken) |
교착 상태와 재진입을 모두 완화하는 방식으로 이 인스턴스가 초기화된 동기화 컨텍스트에서 연속이 실행되는 대기 가능 개체를 가져옵니다. |
SwitchToMainThreadAsync(CancellationToken)
교착 상태와 재진입을 모두 완화하는 방식으로 주 스레드에서 연속이 실행되는 대기 대기자를 가져옵니다.
public Microsoft.VisualStudio.Threading.JoinableTaskFactory.MainThreadAwaitable SwitchToMainThreadAsync(System.Threading.CancellationToken cancellationToken = default);
member this.SwitchToMainThreadAsync : System.Threading.CancellationToken -> Microsoft.VisualStudio.Threading.JoinableTaskFactory.MainThreadAwaitable
Public Function SwitchToMainThreadAsync (Optional cancellationToken As CancellationToken = Nothing) As JoinableTaskFactory.MainThreadAwaitable
매개 변수
- cancellationToken
- CancellationToken
취소가 스레드 풀 스레드에서 연속 작업을 즉시 예약하고 호출자가 이미 주 스레드에 있는 경우에도 연속이 throw OperationCanceledException되는 토큰입니다.
반품
대기자입니다.
예외
호출자가 이미 주 스레드에 있는 경우에도 취소된 경우 cancellationToken 대기 중인 호출자에게 다시 throw됩니다.
설명
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 this.JobContext.SwitchToMainThreadAsync();
STAService.DoSomething();
}
소유 JoinableTaskContext 를 사용하여 nullSynchronizationContext만든 경우 이 메서드는 효과가 없으며 호출자는 원래 스레드에서 실행을 계속합니다.
적용 대상
SwitchToMainThreadAsync(Boolean, CancellationToken)
교착 상태와 재진입을 모두 완화하는 방식으로 이 인스턴스가 초기화된 동기화 컨텍스트에서 연속이 실행되는 대기 가능 개체를 가져옵니다.
public Microsoft.VisualStudio.Threading.JoinableTaskFactory.MainThreadAwaitable SwitchToMainThreadAsync(bool alwaysYield, System.Threading.CancellationToken cancellationToken = default);
member this.SwitchToMainThreadAsync : bool * System.Threading.CancellationToken -> Microsoft.VisualStudio.Threading.JoinableTaskFactory.MainThreadAwaitable
Public Function SwitchToMainThreadAsync (alwaysYield As Boolean, Optional cancellationToken As CancellationToken = Nothing) As JoinableTaskFactory.MainThreadAwaitable
매개 변수
- alwaysYield
- Boolean
주 스레드에서 이미 실행 중인 경우에도 호출자가 생성되어야 하는지 여부를 나타내는 값입니다.
- cancellationToken
- CancellationToken
취소가 스레드 풀 스레드에서 연속 작업을 즉시 예약하고 호출자가 이미 주 스레드에 있는 경우에도 연속이 throw OperationCanceledException되는 토큰입니다.
반품
대기자입니다.
예외
호출자가 이미 주 스레드에 있는 경우에도 취소된 경우 cancellationToken 대기 중인 호출자에게 다시 throw됩니다.
설명
private async Task SomeOperationAsync()
{
// This first part can be on the caller's thread, whatever that is.
DoSomething();
// Now switch to the Main thread to talk to some STA object.
// Supposing it is also important to *not* do this step on our caller's callstack,
// be sure we yield even if we're on the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true);
STAService.DoSomething();
}