AsyncOperationManager 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
비동기 메서드 호출을 지원하는 클래스에 대한 동시성 관리를 제공합니다. 이 클래스는 상속할 수 없습니다.
public ref class AsyncOperationManager abstract sealed
public static class AsyncOperationManager
type AsyncOperationManager = class
Public Class AsyncOperationManager
- 상속
-
AsyncOperationManager
예제
다음 코드 예제에서는 클래스를 AsyncOperationManager 사용하여 모든 애플리케이션 모델에 대한 비동기 작업을 지원하는 클래스를 만드는 방법을 보여 줍니다. 소수인지 여부를 확인하기 위해 숫자를 테스트하는 클래스를 구현하는 방법을 보여 줍니다. 이 계산은 시간이 오래 걸릴 수 있으므로 별도의 스레드에서 수행됩니다. 진행률 보고서, 증분 결과 및 완료 알림은 클래스에서 AsyncOperation 처리되어 클라이언트의 이벤트 처리기가 적절한 스레드 또는 컨텍스트에서 호출되도록 합니다.
클라이언트 양식의 전체 코드 목록은 방법: 이벤트 기반 비동기 패턴의 클라이언트 구현을 참조하세요.
// This method starts an asynchronous calculation.
// First, it checks the supplied task ID for uniqueness.
// If taskId is unique, it creates a new WorkerEventHandler
// and calls its BeginInvoke method to start the calculation.
public virtual void CalculatePrimeAsync(
int numberToTest,
object taskId)
{
// Create an AsyncOperation for taskId.
AsyncOperation asyncOp =
AsyncOperationManager.CreateOperation(taskId);
// Multiple threads will access the task dictionary,
// so it must be locked to serialize access.
lock (userStateToLifetime.SyncRoot)
{
if (userStateToLifetime.Contains(taskId))
{
throw new ArgumentException(
"Task ID parameter must be unique",
nameof(taskId));
}
userStateToLifetime[taskId] = asyncOp;
}
// Start the asynchronous operation.
WorkerEventHandler workerDelegate = new(CalculateWorker);
_ = workerDelegate.BeginInvoke(
numberToTest,
asyncOp,
null,
null);
}
' This method starts an asynchronous calculation.
' First, it checks the supplied task ID for uniqueness.
' If taskId is unique, it creates a new WorkerEventHandler
' and calls its BeginInvoke method to start the calculation.
Public Overridable Sub CalculatePrimeAsync( _
ByVal numberToTest As Integer, _
ByVal taskId As Object)
' Create an AsyncOperation for taskId.
Dim asyncOp As AsyncOperation = _
AsyncOperationManager.CreateOperation(taskId)
' Multiple threads will access the task dictionary,
' so it must be locked to serialize access.
SyncLock userStateToLifetime.SyncRoot
If userStateToLifetime.Contains(taskId) Then
Throw New ArgumentException( _
"Task ID parameter must be unique", _
"taskId")
End If
userStateToLifetime(taskId) = asyncOp
End SyncLock
' Start the asynchronous operation.
Dim workerDelegate As New WorkerEventHandler( _
AddressOf CalculateWorker)
workerDelegate.BeginInvoke( _
numberToTest, _
asyncOp, _
Nothing, _
Nothing)
End Sub
설명
클래스가 이벤트 기반 비동기 패턴 개요에 따라 비동기 동작을 제공해야 하는 경우 여러 동시성 관리 문제가 발생합니다. 이 중에는 애플리케이션 모델(예: Windows Forms 애플리케이션, ASP.NET 애플리케이션, 콘솔 애플리케이션 등)에 적합한 스레드 또는 컨텍스트에서 이벤트 처리기가 호출되도록 하기 위한 요구 사항이 있습니다. AsyncOperationManager .NET Framework에서 지원하는 모든 애플리케이션 모델에서 제대로 실행되는 클래스를 만드는 편리한 방법을 제공합니다.
클래스에는 AsyncOperationManager 특정 비동기 작업의 기간을 추적하는 데 사용할 수 있는 메서드가 하나 CreateOperationSystem.ComponentModel.AsyncOperation 있습니다. System.ComponentModel.AsyncOperation 태스크의 경우 태스크가 완료될 때 클라이언트에 경고하는 데 사용할 수 있습니다. 작업을 종료하지 않고 진행률 업데이트 및 증분 결과를 게시하는 데 사용할 수도 있습니다.
비동기 클래스 구현에 대한 자세한 내용은 이벤트 기반 비동기 패턴 구현을 참조하세요.
속성
| Name | Description |
|---|---|
| SynchronizationContext |
비동기 작업에 대한 동기화 컨텍스트를 가져오거나 설정합니다. |
메서드
| Name | Description |
|---|---|
| CreateOperation(Object) |
AsyncOperation 특정 비동기 작업의 기간을 추적하기 위한 값을 반환합니다. |
적용 대상
추가 정보
- AsyncOperation
- 이벤트 기반 비동기 패턴 구현
- 관리되는 스레딩 모범 사례