WorkflowInstance.GetWorkflowQueueData Méthode

Définition

Obtient une collection d'objets WorkflowQueueInfo contenant les éléments en attente et les activités abonnées pour les files d'attente de workflow associées à cette instance de workflow.

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)

Retours

ReadOnlyCollection<T> d'objets WorkflowQueueInfo.

Exceptions

Le moteur d'exécution de workflow ne s'exécute pas.

Exemples

L'exemple de code suivant montre comment vous pouvez utiliser la méthode GetWorkflowQueueData pour obtenir des informations sur l'état de toutes les files d'attentes de workflow associées à un objet WorkflowInstance. Lorsque l'événement WorkflowIdled se produit, la méthode OnWorkflowIdled définie dans cet exemple est appelée. Il détermine quel workflow est désactivé à l’aide de la propriété WorkflowInstance puis obtient une collection d’éléments en file d’attente pour l’instance de workflow en appelant la méthode GetWorkflowQueueData. Le code itère au sein de la collection pour déterminer quelle activité attend l’événement ayant désactivé le workflow. Il envoie alors une exception à la file d'attente de workflow à l'aide de la méthode EnqueueItem avec le nom de l'élément de la file d'attente de l'événement.

Cet exemple de code fait partie de l'exemple du Kit de développement logiciel Canceling a Workflow (SDK) et provient du fichier Program.cs. Pour plus d’informations, consultez Annulation d’un flux de travail.

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

Remarques

GetWorkflowQueueData renvoie une collection d'objets WorkflowQueueInfo, dont chacun contient des informations sur l'état de l'une des files d'attente de flux de travail associée à cette instance de flux de travail. WorkflowQueueInfo.Items contient les éléments en attente pour WorkflowQueue et WorkflowQueueInfo.SubscribedActivityNames contient une liste des activités souscrites pour la remise d'élément dans WorkflowQueue.

S’applique à

Voir aussi