WorkflowInstance.Terminate Method (String)


Terminates the workflow instance in a synchronous manner.

Namespace:   System.Workflow.Runtime
Assembly:  System.Workflow.Runtime (in System.Workflow.Runtime.dll)

public void Terminate(
	string error


Type: System.String

A description of the reason for terminating the workflow instance.

Exception Condition

The workflow runtime engine is not running.

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.

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
// Terminate the workflow, passing in a message
workflowInstance.Terminate("Workflow manually terminated");

.NET Framework
Available since 3.0
Return to top