Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Terminates a workflow instance.
Terminate(Exception) |
Terminates a workflow instance using the specified exception. |
Terminate(String) |
Terminates a workflow instance using the specified error message. |
Terminate(Exception, TimeSpan) |
Terminates a workflow instance using the specified exception and time-out interval. |
Terminate(String, TimeSpan) |
Terminates a workflow instance using the specified error message and time-out interval. |
Terminates a workflow instance using the specified exception.
public:
void Terminate(Exception ^ reason);
public void Terminate(Exception reason);
member this.Terminate : Exception -> unit
Public Sub Terminate (reason As Exception)
The reason for terminating the workflow instance.
The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using the specified workflow definition, the desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. After the workflow is started, Terminate is called. When the workflow is terminated, the following output is displayed to the console.
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."));
This method schedules the termination of the workflow instance. To be notified when the termination has completed, use the Completed handle.
By default, the Terminate operation must complete in 30 seconds or a TimeoutException is thrown.
Product | Versions |
---|---|
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Terminates a workflow instance using the specified error message.
public:
void Terminate(System::String ^ reason);
public void Terminate(string reason);
member this.Terminate : string -> unit
Public Sub Terminate (reason As String)
The reason for terminating the workflow instance.
The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using the specified workflow definition, the desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. After the workflow is started, Terminate is called. When the workflow is terminated, the following output is displayed to the console.
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.");
This method schedules the termination of the workflow instance. To be notified when the termination has completed, use the Completed handle.
By default, the Terminate operation must complete in 30 seconds or a TimeoutException is thrown.
Product | Versions |
---|---|
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Terminates a workflow instance using the specified exception and time-out interval.
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)
The reason for terminating the workflow instance.
The interval in which the Terminate(Exception, TimeSpan) operation must complete before the operation is canceled and a TimeoutException is thrown.
The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using the specified workflow definition, the desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. After the workflow is started, Terminate is called. When the workflow is terminated, the following output is displayed to the console.
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));
This method schedules the termination of the workflow. To be notified when the termination has completed, use the Completed handle.
Product | Versions |
---|---|
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Terminates a workflow instance using the specified error message and time-out interval.
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)
The reason for terminating the workflow instance.
The interval in which the Terminate(String, TimeSpan) operation must complete before the operation is canceled and a TimeoutException is thrown.
The following example hosts a workflow using WorkflowApplication. A WorkflowApplication instance is constructed using the specified workflow definition, the desired workflow lifecycle events are handled, and the workflow is invoked with a call to Run. After the workflow is started, Terminate is called. When the workflow is terminated, the following output is displayed to the console.
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));
This method schedules the termination of the workflow instance. To be notified when the termination has completed, use the Completed handle.
Product | Versions |
---|---|
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in