WorkflowApplication.Run メソッド

定義

ワークフロー インスタンスの実行を開始または再開します。

オーバーロード

名前 説明
Run()

ワークフロー インスタンスの実行を開始または再開します。

Run(TimeSpan)

指定したタイムアウト間隔を使用して、ワークフロー インスタンスの実行を開始または再開します。

注釈

このメソッドを呼び出して、新しく作成されたワークフロー インスタンスの実行を開始します。

Run()

ワークフロー インスタンスの実行を開始または再開します。

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

次の例では、 WorkflowApplicationを使用してワークフローをホストします。 WorkflowApplication インスタンスは、指定されたワークフロー定義を使用して構築され、目的のワークフロー ライフサイクル イベントが処理され、ワークフローはRunの呼び出しで呼び出されます。 ワークフローが完了すると、次の出力がコンソールに表示されます。

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();

注釈

このメソッドを呼び出して、新しく作成されたワークフロー インスタンスの実行を開始します。

実行操作が 30 秒以内に完了しない場合は、 TimeoutException がスローされます。

適用対象

Run(TimeSpan)

指定したタイムアウト間隔を使用して、ワークフロー インスタンスの実行を開始または再開します。

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

パラメーター

timeout
TimeSpan

このメソッドを呼び出して、新しく作成されたワークフロー インスタンスの実行を開始します。

操作が取り消され、 TimeoutException がスローされるまでに実行操作を完了する必要がある間隔。

次の例では、 WorkflowApplicationを使用してワークフローをホストします。 WorkflowApplication インスタンスは、指定されたワークフロー定義を使用して構築され、目的のワークフロー ライフサイクル イベントが処理され、ワークフローはRunの呼び出しで呼び出されます。 ワークフローが完了すると、次の出力がコンソールに表示されます。

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();

注釈

Invokeとは異なり、このメソッドは、指定した時間内にワークフローが開始されない場合にのみタイムアウトします。ただし、指定した時間内に完了する必要はありません。 その理由は、 Invoke はワークフローを同期的に実行し (ホスト スレッドをブロックする)、 Run は非同期的に実行し、ワークフローの開始に要する時間だけホスト スレッドをブロックするためです。

適用対象