AsyncOperationManager 클래스

정의

비동기 메서드 호출을 지원하는 클래스에 대한 동시성 관리 기능을 제공합니다. 이 클래스는 상속될 수 없습니다.

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", 
                "taskId");
        }

        userStateToLifetime[taskId] = asyncOp;
    }

    // Start the asynchronous operation.
    WorkerEventHandler workerDelegate = new WorkerEventHandler(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 특정 비동기 작업의 기간을 추적하는 데 사용할 수 있는 를 반환 System.ComponentModel.AsyncOperation 하는 메서드가 하나 CreateOperation있습니다. 태스크에 대한 는 System.ComponentModel.AsyncOperation 태스크가 완료될 때 클라이언트에 경고하는 데 사용할 수 있습니다. 또한 작업을 종료하지 않고 진행률 업데이트 및 증분 결과를 게시하는 데 사용할 수 있습니다.

비동기 클래스 구현에 대한 자세한 내용은 이벤트 기반 비동기 패턴 구현을 참조하세요.

속성

SynchronizationContext

비동기 작업의 동기화 컨텍스트를 가져오거나 설정합니다.

메서드

CreateOperation(Object)

특정 비동기 작업의 기간을 추적하기 위한 AsyncOperation을 반환합니다.

적용 대상

추가 정보