다음을 통해 공유


WorkflowEventArgs.WorkflowInstance 속성

정의

워크플로 이벤트와 연결된 워크플로 인스턴스를 가져옵니다.

public:
 property System::Workflow::Runtime::WorkflowInstance ^ WorkflowInstance { System::Workflow::Runtime::WorkflowInstance ^ get(); };
public System.Workflow.Runtime.WorkflowInstance WorkflowInstance { get; }
member this.WorkflowInstance : System.Workflow.Runtime.WorkflowInstance
Public ReadOnly Property WorkflowInstance As WorkflowInstance

속성 값

워크플로 이벤트와 연결된 WorkflowInstance입니다.

예제

다음 코드 예제에서는 이벤트 처리기 메서드를 호출할 때 WorkflowInstance 속성을 사용하여 WorkflowInstance 개체를 가져오는 방법을 보여 줍니다. WorkflowIdled 이벤트가 발생하면 이 예제에서 정의된 OnWorkflowIdled 메서드가 호출됩니다. WorkflowInstance 속성을 사용하여 유휴 상태인 워크플로를 확인한 다음 GetWorkflowQueueData 메서드를 호출하여 워크플로 인스턴스에 대해 큐 항목 컬렉션을 가져옵니다. 이 코드는 컬렉션을 반복하여 워크플로를 유휴 상태로 만든 이벤트를 기다리고 있는 활동을 확인합니다. 그런 다음 이벤트 큐 항목의 이름과 함께 EnqueueItem 메서드를 사용하여 워크플로 큐에 예외를 보냅니다.

이 코드 예제는 Program.cs 파일에 있는 Canceling a Workflow SDK 샘플의 일부입니다. 자세한 내용은 워크플로 취소 하면합니다.

static void OnWorkflowIdled(object sender, WorkflowEventArgs e)
{
    WorkflowInstance workflow = e.WorkflowInstance;

    Console.WriteLine("\n...waiting for 3 seconds... \n");
    Thread.Sleep(3000);

    // what activity is blocking the workflow
    ReadOnlyCollection<WorkflowQueueInfo> wqi = workflow.GetWorkflowQueueData();
    foreach (WorkflowQueueInfo q in wqi)
    {
        EventQueueName eq = q.QueueName as EventQueueName;
        if (eq != null)
        {
            // get activity that is waiting for event
            ReadOnlyCollection<string> blockedActivity = q.SubscribedActivityNames;
            Console.WriteLine("Host: Workflow is blocked on " + blockedActivity[0]);

            // this event is never going to arrive eg. employee left the company
            // lets send an exception to this queue
            // it will either be handled by exception handler that was modeled in workflow
            // or the runtime will unwind running compensation handlers and exit the workflow
            Console.WriteLine("Host: This event is not going to arrive");
            Console.WriteLine("Host: Cancel workflow with unhandled exception");
            workflow.EnqueueItem(q.QueueName, new Exception("ExitWorkflowException"), null, null);
        }
    }
}
Shared Sub OnWorkflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs)
    Dim workflow As WorkflowInstance = e.WorkflowInstance

    Console.WriteLine(vbCrLf + "...waiting for 3 seconds... " + vbCrLf)
    Thread.Sleep(3000)

    ' what activity is blocking the workflow
    Dim wqi As ReadOnlyCollection(Of WorkflowQueueInfo) = workflow.GetWorkflowQueueData()
    For Each q As WorkflowQueueInfo In wqi

        Dim eq As EventQueueName = TryCast(q.QueueName, EventQueueName)

        If eq IsNot Nothing Then
            ' get activity that is waiting for event
            Dim blockedActivity As ReadOnlyCollection(Of String) = q.SubscribedActivityNames
            Console.WriteLine("Host: Workflow is blocked on " + blockedActivity(0))

            ' this event is never going to arrive eg. employee left the company
            ' lets send an exception to this queue
            ' it will either be handled by exception handler that was modeled in workflow
            ' or the runtime will unwind running compensation handlers and exit the workflow
            Console.WriteLine("Host: This event is not going to arrive")
            Console.WriteLine("Host: Cancel workflow with unhandled exception")
            workflow.EnqueueItem(q.QueueName, New Exception("ExitWorkflowException"), Nothing, Nothing)
        End If
    Next
End Sub

적용 대상

추가 정보