共用方式為


WorkflowApplication.Terminate 方法

定義

終止工作流程執行個體。

多載

Terminate(Exception)

使用指定的例外狀況,終止工作流程執行個體。

Terminate(String)

使用指定的錯誤訊息,終止工作流程執行個體。

Terminate(Exception, TimeSpan)

使用指定的例外狀況和逾時間隔,終止工作流程執行個體。

Terminate(String, TimeSpan)

使用指定的錯誤訊息和逾時間隔,終止工作流程執行個體。

Terminate(Exception)

使用指定的例外狀況,終止工作流程執行個體。

public:
 void Terminate(Exception ^ reason);
public void Terminate (Exception reason);
member this.Terminate : Exception -> unit
Public Sub Terminate (reason As Exception)

參數

reason
Exception

終止工作流程執行個體的原因。

範例

下列範例會使用 WorkflowApplication 來裝載工作流程。 系統會使用指定的工作流程定義來建構 WorkflowApplication 執行個體、處理所需的工作流程開發週期事件,並且透過呼叫 Run 叫用此工作流程。 啟動工作流程之後,就會呼叫 Terminate。 當工作流程終止時,主控台就會顯示下列輸出。

Starting the workflow.   
Workflow e6b33409-f010-49f1-82ce-56f8baabe5e5 Terminated.  
Exception: System.ApplicationException  
Terminating the workflow.   
Workflow e6b33409-f010-49f1-82ce-56f8baabe5e5 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.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} unloaded.", e.InstanceId);
};

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

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Terminate(new ApplicationException("Terminating the workflow."));

備註

此方法會排程工作流程執行個體的終止。 若要在終止完成時收到通知,請使用 Completed 控制代碼。

根據預設,Terminate 作業必須在 30 秒內完成,否則會擲回 TimeoutException

適用於

Terminate(String)

使用指定的錯誤訊息,終止工作流程執行個體。

public:
 void Terminate(System::String ^ reason);
public void Terminate (string reason);
member this.Terminate : string -> unit
Public Sub Terminate (reason As String)

參數

reason
String

終止工作流程執行個體的原因。

範例

下列範例會使用 WorkflowApplication 來裝載工作流程。 系統會使用指定的工作流程定義來建構 WorkflowApplication 執行個體、處理所需的工作流程開發週期事件,並且透過呼叫 Run 叫用此工作流程。 啟動工作流程之後,就會呼叫 Terminate。 當工作流程終止時,主控台就會顯示下列輸出。

Starting the workflow.   
Workflow f87c6f91-4fe4-40b9-b7cb-4f1bd071bf84 Terminated.   
Exception: System.Activities.WorkflowApplicationTerminatedException  
Terminating the workflow.   
Workflow f87c6f91-4fe4-40b9-b7cb-4f1bd071bf84 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.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} unloaded.", e.InstanceId);
};

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

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Terminate("Terminating the workflow.");

備註

此方法會排程工作流程執行個體的終止。 若要在終止完成時收到通知,請使用 Completed 控制代碼。

根據預設,Terminate 作業必須在 30 秒內完成,否則會擲回 TimeoutException

適用於

Terminate(Exception, TimeSpan)

使用指定的例外狀況和逾時間隔,終止工作流程執行個體。

public:
 void Terminate(Exception ^ reason, TimeSpan timeout);
public void Terminate (Exception reason, TimeSpan timeout);
member this.Terminate : Exception * TimeSpan -> unit
Public Sub Terminate (reason As Exception, timeout As TimeSpan)

參數

reason
Exception

終止工作流程執行個體的原因。

timeout
TimeSpan

Terminate(Exception, TimeSpan) 作業必須在作業取消並擲回 TimeoutException 前完成的間隔。

範例

下列範例會使用 WorkflowApplication 來裝載工作流程。 系統會使用指定的工作流程定義來建構 WorkflowApplication 執行個體、處理所需的工作流程開發週期事件,並且透過呼叫 Run 叫用此工作流程。 啟動工作流程之後,就會呼叫 Terminate。 當工作流程終止時,主控台就會顯示下列輸出。

Starting the workflow.   
Workflow de28efe5-9057-472b-8d95-899c249893c5 Terminated.  
Exception: System.ApplicationException  
Terminating the workflow.   
Workflow de28efe5-9057-472b-8d95-899c249893c5 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.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} unloaded.", e.InstanceId);
};

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

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Terminate(new ApplicationException("Terminating the workflow."),
    TimeSpan.FromSeconds(15));

備註

此方法會排程終止工作流程。 若要在終止完成時收到通知,請使用 Completed 控制代碼。

適用於

Terminate(String, TimeSpan)

使用指定的錯誤訊息和逾時間隔,終止工作流程執行個體。

public:
 void Terminate(System::String ^ reason, TimeSpan timeout);
public void Terminate (string reason, TimeSpan timeout);
member this.Terminate : string * TimeSpan -> unit
Public Sub Terminate (reason As String, timeout As TimeSpan)

參數

reason
String

終止工作流程執行個體的原因。

timeout
TimeSpan

Terminate(String, TimeSpan) 作業必須在作業取消並擲回 TimeoutException 前完成的間隔。

範例

下列範例會使用 WorkflowApplication 來裝載工作流程。 系統會使用指定的工作流程定義來建構 WorkflowApplication 執行個體、處理所需的工作流程開發週期事件,並且透過呼叫 Run 叫用此工作流程。 啟動工作流程之後,就會呼叫 Terminate。 當工作流程終止時,主控台就會顯示下列輸出。

Starting the workflow.   
Workflow 2897d2ef-377e-4224-ae93-5c19b38f487c Terminated.   
Exception: System.Activities.WorkflowApplicationTerminatedException  
Terminating the workflow.   
Workflow 2897d2ef-377e-4224-ae93-5c19b38f487c 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.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
    Console.WriteLine("Workflow {0} unloaded.", e.InstanceId);
};

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

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Terminate("Terminating the workflow.", TimeSpan.FromSeconds(15));

備註

此方法會排程工作流程執行個體的終止。 若要在終止完成時收到通知,請使用 Completed 控制代碼。

適用於