WorkflowInstance.EnqueueItem 메서드

정의

메시지를 지정된 워크플로 큐에 동기적으로 게시합니다.

public:
 void EnqueueItem(IComparable ^ queueName, System::Object ^ item, System::Workflow::Runtime::IPendingWork ^ pendingWork, System::Object ^ workItem);
public void EnqueueItem (IComparable queueName, object item, System.Workflow.Runtime.IPendingWork pendingWork, object workItem);
member this.EnqueueItem : IComparable * obj * System.Workflow.Runtime.IPendingWork * obj -> unit
Public Sub EnqueueItem (queueName As IComparable, item As Object, pendingWork As IPendingWork, workItem As Object)

매개 변수

queueName
IComparable

WorkflowQueue의 이름입니다.

item
Object

큐에 삽입할 개체입니다.

pendingWork
IPendingWork

IPendingWork이 전달되면 발신자에게 알리는 item입니다.

workItem
Object

IPendingWork 메서드에 전달할 개체입니다.

예외

queueName이 null 참조(Visual Basic의 경우 Nothing)인 경우

워크플로 런타임 엔진이 실행되고 있지 않은 경우

또는

WorkflowQueue에 지정된 queueName가 없는 경우

또는

WorkflowQueue에 지정된 queueName를 사용할 수 없는 경우

예제

다음 코드 예제에서는 EnqueueItem을 사용하는 방법을 보여 줍니다. 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

설명

item을 지정된 WorkflowQueue로 보냅니다. 메시지가 전달될 때 알림을 받으려면 서비스에 IPendingWork를 구현하고 workItemIPendingWork 개체를 EnqueueItem으로 전달합니다. 해당 알림을 원하지 않는 경우 NothingpendingWork에 대해 null 참조(Visual Basic의 경우 workItem)를 전달할 수 있습니다.

상태 컴퓨터 워크플로에서 이 메서드를 사용하는 경우 "큐 '{0}'를 사용할 수 없습니다."라는 메시지와 함께 예외가 발생할 수 있습니다. 이는 상태 컴퓨터의 현재 상태가 특정 이벤트를 처리하는 방법을 모를 때 발생합니다. 예를 들어 현재 상태 이외의 일부 상태에 '{0}' 큐에서 나타내는 EventDrivenActivity를 포함하는 HandleExternalEventActivity가 있습니다.

참고

메시지가 전송된 순서대로 워크플로 인스턴스에 메시지가 수신된다고 보장할 수는 없습니다. 예를 들어 기존 큐(큐 A)에서 메시지를 받고 있으면 워크플로가 다른 큐(큐 B)를 만들게 되고, 이 큐가 첫 번째 메시지 이후에 전송된 다른 메시지를 수신 대기하는 경우 두 번째 메시지가 먼저 도착하지만 해당 큐가 아직 만들어지지 않아서 수신되지 않을 수 있습니다. 이 문제를 방지하려면 GetWorkflowQueueData를 사용하여 두 번째 큐가 있는지 확인할 때까지 두 번째 메시지를 보내지 않아야 합니다.

적용 대상

추가 정보