แก้ไข

แชร์ผ่าน


WorkflowInstance.Terminate(String) Method

Definition

Terminates the workflow instance in a synchronous manner.

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

Parameters

error
String

A description of the reason for terminating the workflow instance.

Exceptions

The workflow runtime engine is not running.

Examples

The following code example demonstrates calling Terminate on a WorkflowInstance object.

// Create a workflow runtime
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
// Create a workflow instance
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(Workflow1));
// Start the workflow
workflowInstance.Start();
// Terminate the workflow, passing in a message
workflowInstance.Terminate("Workflow manually terminated");
' Create a workflow runtime
Dim workflowRuntime As New WorkflowRuntime()
' Create a workflow instance
Dim workflowInstance As WorkflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1))
' Start the workflow
workflowInstance.Start()
' Terminate the workflow, passing in a message
workflowInstance.Terminate("Workflow manually terminated")

Remarks

The workflow instance is terminated in a synchronous manner. The host calls Terminate to terminate the workflow instance. The workflow runtime engine clears the in-memory workflow instance and informs the persistence service that the instance has been cleared from memory. For the SqlWorkflowPersistenceService, this means that all state information for that workflow instance is deleted from the database upon termination. You will not be able to reload the workflow instance from a previously stored persistence point.

After the in-memory workflow instance is cleared and the persistence service is informed of the termination, the Terminate method raises the WorkflowTerminated event and passes reason in the Message property of a WorkflowTerminatedException contained in the WorkflowTerminatedEventArgs.

Terminate is different from Abort in that while Terminate clears the in-memory workflow instance and informs the persistence service of the termination, Abort simply clears the in-memory workflow instance, which can then be restarted from the last persistence point.

Applies to