Share via


WorkflowInstance.GetWorkflowQueueData Método

Definição

Obtém uma coleção de objetos WorkflowQueueInfo que contém os itens pendentes e as atividades assinadas das filas de fluxo de trabalho associadas a esta instância de fluxo de trabalho.

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)

Retornos

Uma ReadOnlyCollection<T> de objetos WorkflowQueueInfo.

Exceções

O mecanismo de runtime de fluxo de trabalho não está em execução.

Exemplos

O exemplo de código a seguir demonstra como você pode usar o GetWorkflowQueueData método para obter informações sobre o estado de todas as filas de fluxo de trabalho associadas a um WorkflowInstance objeto . Quando o WorkflowIdled evento ocorre, o OnWorkflowIdled método definido neste exemplo é chamado. Ele determina qual fluxo de trabalho está ocioso usando a WorkflowInstance propriedade e obtém uma coleção de itens enfileirados para a instância de fluxo de trabalho chamando o GetWorkflowQueueData método . O código itera sobre a coleção para determinar qual atividade está aguardando o evento que ociosidade do fluxo de trabalho. Em seguida, ele envia uma exceção para a fila de fluxo de trabalho usando o EnqueueItem método junto com o nome do item da fila de eventos.

Este exemplo de código faz parte do exemplo Canceling a Workflow SDK do arquivo Program.cs. Para obter mais informações, consulte Cancelando um fluxo de trabalho.

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

Comentários

GetWorkflowQueueData retorna uma coleção de WorkflowQueueInfo objetos , cada um dos quais contém informações sobre o estado de uma das filas de fluxo de trabalho associadas a essa instância de fluxo de trabalho. WorkflowQueueInfo.Items contém os itens pendentes para um WorkflowQueue e WorkflowQueueInfo.SubscribedActivityNames contém uma lista das atividades que são assinadas para entrega de item em um WorkflowQueue.

Aplica-se a

Confira também