WorkflowEventArgs.WorkflowInstance Propiedad

Definición

Obtiene la instancia de flujo de trabajo asociada al evento de flujo de trabajo.

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

Valor de propiedad

WorkflowInstance asociado al evento de flujo de trabajo.

Ejemplos

El ejemplo de código siguiente muestra cómo obtener un objeto WorkflowInstance mediante la propiedad WorkflowInstance cuando se llama a un método de control de eventos. Cuando se produce el evento WorkflowIdled, se llama al método OnWorkflowIdled definido en este ejemplo. Determina qué flujo de trabajo está inactivo utilizando la propiedad WorkflowInstance y, a continuación, obtiene una colección de elementos en cola para la instancia de flujo de trabajo llamando al método GetWorkflowQueueData. El código itera sobre la colección para determinar qué actividad está esperando para el evento que ralentizó el flujo de trabajo. Envía a continuación una excepción a la cola del flujo de trabajo utilizando el método EnqueueItem junto con el nombre del elemento de cola de evento.

Este ejemplo de código forma parte de la muestra de SDK Cancelar un Flujo de trabajo, del archivo Program.cs. Para obtener más información, consulte Cancelación de un flujo de trabajo.

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

Se aplica a

Consulte también