Redigera

Dela via


WorkflowInstance.GetWorkflowQueueData Method

Definition

Gets a collection of WorkflowQueueInfo objects that contains the pending items and subscribed activities for the workflow queues associated with this workflow instance.

public:
 System::Collections::ObjectModel::ReadOnlyCollection<System::Workflow::Runtime::WorkflowQueueInfo ^> ^ GetWorkflowQueueData();
public System.Collections.ObjectModel.ReadOnlyCollection<System.Workflow.Runtime.WorkflowQueueInfo> GetWorkflowQueueData ();
member this.GetWorkflowQueueData : unit -> System.Collections.ObjectModel.ReadOnlyCollection<System.Workflow.Runtime.WorkflowQueueInfo>
Public Function GetWorkflowQueueData () As ReadOnlyCollection(Of WorkflowQueueInfo)

Returns

A ReadOnlyCollection<T> of WorkflowQueueInfo objects.

Exceptions

The workflow runtime engine is not running.

Examples

The following code example demonstrates how you can use the GetWorkflowQueueData method to obtain information about the state of all workflow queues associated with a WorkflowInstance object. When the WorkflowIdled event occurs, the OnWorkflowIdled method defined in this example is called. It determines which workflow is idled using the WorkflowInstance property and then gets a collection of queued items for the workflow instance by calling the GetWorkflowQueueData method. The code iterates over the collection to determine which activity is waiting for the event that idled the workflow. It then sends an exception to the workflow queue using the EnqueueItem method along with the name of the event queue item.

This code example is part of the Canceling a Workflow SDK sample from the Program.cs file. For more information, see Canceling a Workflow.

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

Remarks

GetWorkflowQueueData returns a collection of WorkflowQueueInfo objects, each of which contains information about the state of one of the workflow queues associated with this workflow instance. WorkflowQueueInfo.Items contains the pending items for a WorkflowQueue and WorkflowQueueInfo.SubscribedActivityNames contains a list of the activities that are subscribed for item delivery on a WorkflowQueue.

Applies to

See also