WorkflowApplication.Run Método

Definición

Comienza o reanuda la ejecución de una instancia de flujo de trabajo.

Sobrecargas

Nombre Description
Run()

Comienza o reanuda la ejecución de una instancia de flujo de trabajo.

Run(TimeSpan)

Comienza o reanuda la ejecución de una instancia de flujo de trabajo mediante el intervalo de tiempo de espera especificado.

Comentarios

Llame a este método para iniciar la ejecución de una instancia de flujo de trabajo recién creada.

Run()

Comienza o reanuda la ejecución de una instancia de flujo de trabajo.

public:
 void Run();
public void Run();
member this.Run : unit -> unit
Public Sub Run ()

Ejemplos

En el ejemplo siguiente se hospeda un flujo de trabajo mediante WorkflowApplication. Una WorkflowApplication instancia se construye mediante la definición de flujo de trabajo especificada, se controlan los eventos de ciclo de vida de flujo de trabajo deseados y el flujo de trabajo se invoca con una llamada a Run. Cuando se completa el flujo de trabajo, se muestra la salida siguiente en la consola.

Starting the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Idle.
Ending the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Completed
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Unloaded.
Activity wf = new Sequence
{
    Activities =
     {
         new WriteLine
         {
             Text = "Starting the workflow."
         },
         new Delay
         {
             Duration = TimeSpan.FromSeconds(5)
         },
         new WriteLine
         {
             Text = "Ending the workflow."
         }
     }
};

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Subscribe to any desired workflow lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Outputs can be retrieved from the Outputs dictionary,
        // keyed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Perform any processing that should occur
    // when a workflow goes idle. If the workflow can persist,
    // both Idle and PersistableIdle are called in that order.
    Console.WriteLine("Workflow {0} Idle.", e.InstanceId);
};

wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Instruct the runtime to persist and unload the workflow
    return PersistableIdleAction.Unload;
};

wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId);
};

wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    // Display the unhandled exception.
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);

    // Instruct the runtime to terminate the workflow.
    // Other choices are Abort and Cancel
    return UnhandledExceptionAction.Terminate;
};

// Run the workflow.
wfApp.Run();

Comentarios

Llame a este método para iniciar la ejecución de una instancia de flujo de trabajo recién creada.

Si la operación de ejecución no se completa en un plazo de 30 segundos, se produce una TimeoutException excepción .

Se aplica a

Run(TimeSpan)

Comienza o reanuda la ejecución de una instancia de flujo de trabajo mediante el intervalo de tiempo de espera especificado.

public:
 void Run(TimeSpan timeout);
public void Run(TimeSpan timeout);
member this.Run : TimeSpan -> unit
Public Sub Run (timeout As TimeSpan)

Parámetros

timeout
TimeSpan

Llame a este método para iniciar la ejecución de una instancia de flujo de trabajo recién creada.

Intervalo en el que se debe completar la operación de ejecución antes de que se cancele la operación y se produzca una TimeoutException excepción .

Ejemplos

En el ejemplo siguiente se hospeda un flujo de trabajo mediante WorkflowApplication. Una WorkflowApplication instancia se construye mediante la definición de flujo de trabajo especificada, se controlan los eventos de ciclo de vida de flujo de trabajo deseados y el flujo de trabajo se invoca con una llamada a Run. Cuando se completa el flujo de trabajo, se muestra la salida siguiente en la consola.

Starting the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Idle.
Ending the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Completed
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Unloaded.
Activity wf = new Sequence
{
    Activities =
     {
         new WriteLine
         {
             Text = "Starting the workflow."
         },
         new Delay
         {
             Duration = TimeSpan.FromSeconds(5)
         },
         new WriteLine
         {
             Text = "Ending the workflow."
         }
     }
};

// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Subscribe to any desired workflow lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    if (e.CompletionState == ActivityInstanceState.Faulted)
    {
        Console.WriteLine("Workflow {0} Terminated.", e.InstanceId);
        Console.WriteLine("Exception: {0}\n{1}",
            e.TerminationException.GetType().FullName,
            e.TerminationException.Message);
    }
    else if (e.CompletionState == ActivityInstanceState.Canceled)
    {
        Console.WriteLine("Workflow {0} Canceled.", e.InstanceId);
    }
    else
    {
        Console.WriteLine("Workflow {0} Completed.", e.InstanceId);

        // Outputs can be retrieved from the Outputs dictionary,
        // keyed by argument name.
        // Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
    }
};

wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
    // Display the exception that caused the workflow
    // to abort.
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
    Console.WriteLine("Exception: {0}\n{1}",
        e.Reason.GetType().FullName,
        e.Reason.Message);
};

wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Perform any processing that should occur
    // when a workflow goes idle. If the workflow can persist,
    // both Idle and PersistableIdle are called in that order.
    Console.WriteLine("Workflow {0} Idle.", e.InstanceId);
};

wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
    // Instruct the runtime to persist and unload the workflow
    return PersistableIdleAction.Unload;
};

wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId);
};

wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    // Display the unhandled exception.
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);

    // Instruct the runtime to terminate the workflow.
    // Other choices are Abort and Cancel
    return UnhandledExceptionAction.Terminate;
};

// Run the workflow.
wfApp.Run();

Comentarios

Tenga en cuenta que, a diferencia Invokede , este método agotará el tiempo de espera solo si el flujo de trabajo no se inicia en la cantidad de tiempo especificada, en lugar de necesitar completarse en la cantidad de tiempo especificada. El motivo de esto es que Invoke ejecuta el flujo de trabajo de forma sincrónica (bloqueando el subproceso de host), mientras se Run ejecuta de forma asincrónica, solo bloqueando el subproceso host durante el tiempo que tarda el flujo de trabajo en iniciarse.

Se aplica a