WorkflowApplication.Terminate Metod

Definition

Avslutar en arbetsflödesinstans.

Överlagringar

Name Description
Terminate(Exception)

Avslutar en arbetsflödesinstans med det angivna undantaget.

Terminate(String)

Avslutar en arbetsflödesinstans med det angivna felmeddelandet.

Terminate(Exception, TimeSpan)

Avslutar en arbetsflödesinstans med det angivna undantaget och tidsgränsintervallet.

Terminate(String, TimeSpan)

Avslutar en arbetsflödesinstans med det angivna felmeddelandet och tidsgränsintervallet.

Terminate(Exception)

Avslutar en arbetsflödesinstans med det angivna undantaget.

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

Parametrar

reason
Exception

Anledningen till att avsluta arbetsflödesinstansen.

Exempel

I följande exempel finns ett arbetsflöde med .WorkflowApplication En WorkflowApplication instans skapas med den angivna arbetsflödesdefinitionen, önskade livscykelhändelser för arbetsflödet hanteras och arbetsflödet anropas med ett anrop till Run. När arbetsflödet har startats Terminate anropas. När arbetsflödet avslutas visas följande utdata i konsolen.

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."));

Kommentarer

Den här metoden schemalägger avslutningen av arbetsflödesinstansen. Använd handtaget för att meddelas när uppsägningen har slutförts Completed .

Som standard måste åtgärden Terminate slutföras om 30 sekunder eller så genereras en TimeoutException .

Gäller för

Terminate(String)

Avslutar en arbetsflödesinstans med det angivna felmeddelandet.

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

Parametrar

reason
String

Anledningen till att avsluta arbetsflödesinstansen.

Exempel

I följande exempel finns ett arbetsflöde med .WorkflowApplication En WorkflowApplication instans skapas med den angivna arbetsflödesdefinitionen, önskade livscykelhändelser för arbetsflödet hanteras och arbetsflödet anropas med ett anrop till Run. När arbetsflödet har startats Terminate anropas. När arbetsflödet avslutas visas följande utdata i konsolen.

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.");

Kommentarer

Den här metoden schemalägger avslutningen av arbetsflödesinstansen. Använd handtaget för att meddelas när uppsägningen har slutförts Completed .

Som standard måste åtgärden Terminate slutföras om 30 sekunder eller så genereras en TimeoutException .

Gäller för

Terminate(Exception, TimeSpan)

Avslutar en arbetsflödesinstans med det angivna undantaget och tidsgränsintervallet.

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)

Parametrar

reason
Exception

Anledningen till att avsluta arbetsflödesinstansen.

timeout
TimeSpan

Intervallet då Terminate(Exception, TimeSpan) åtgärden måste slutföras innan åtgärden avbryts och en TimeoutException genereras.

Exempel

I följande exempel finns ett arbetsflöde med .WorkflowApplication En WorkflowApplication instans skapas med den angivna arbetsflödesdefinitionen, önskade livscykelhändelser för arbetsflödet hanteras och arbetsflödet anropas med ett anrop till Run. När arbetsflödet har startats Terminate anropas. När arbetsflödet avslutas visas följande utdata i konsolen.

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

Kommentarer

Den här metoden schemalägger avslutningen av arbetsflödet. Använd handtaget för att meddelas när uppsägningen har slutförts Completed .

Gäller för

Terminate(String, TimeSpan)

Avslutar en arbetsflödesinstans med det angivna felmeddelandet och tidsgränsintervallet.

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)

Parametrar

reason
String

Anledningen till att avsluta arbetsflödesinstansen.

timeout
TimeSpan

Intervallet då Terminate(String, TimeSpan) åtgärden måste slutföras innan åtgärden avbryts och en TimeoutException genereras.

Exempel

I följande exempel finns ett arbetsflöde med .WorkflowApplication En WorkflowApplication instans skapas med den angivna arbetsflödesdefinitionen, önskade livscykelhändelser för arbetsflödet hanteras och arbetsflödet anropas med ett anrop till Run. När arbetsflödet har startats Terminate anropas. När arbetsflödet avslutas visas följande utdata i konsolen.

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

Kommentarer

Den här metoden schemalägger avslutningen av arbetsflödesinstansen. Använd handtaget för att meddelas när uppsägningen har slutförts Completed .

Gäller för