Bagikan melalui


WorkflowApplication.Terminate Metode

Definisi

Mengakhiri instans alur kerja.

Overload

Terminate(Exception)

Mengakhiri instans alur kerja menggunakan pengecualian yang ditentukan.

Terminate(String)

Mengakhiri instans alur kerja menggunakan pesan kesalahan yang ditentukan.

Terminate(Exception, TimeSpan)

Mengakhiri instans alur kerja menggunakan pengecualian dan interval waktu habis yang ditentukan.

Terminate(String, TimeSpan)

Mengakhiri instans alur kerja menggunakan pesan kesalahan dan interval waktu habis yang ditentukan.

Terminate(Exception)

Mengakhiri instans alur kerja menggunakan pengecualian yang ditentukan.

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

Parameter

reason
Exception

Alasan untuk mengakhiri instans alur kerja.

Contoh

Contoh berikut meng-hosting alur kerja menggunakan WorkflowApplication. WorkflowApplication Instans dibangun menggunakan definisi alur kerja yang ditentukan, peristiwa siklus hidup alur kerja yang diinginkan ditangani, dan alur kerja dipanggil dengan panggilan ke Run. Setelah alur kerja dimulai, Terminate dipanggil. Saat alur kerja dihentikan, output berikut ditampilkan ke konsol.

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

Keterangan

Metode ini menjadwalkan penghentian instans alur kerja. Untuk diberi tahu ketika penghentian telah selesai, gunakan Completed handel.

Secara default, Terminate operasi harus selesai dalam 30 detik atau dilemparkan TimeoutException .

Berlaku untuk

Terminate(String)

Mengakhiri instans alur kerja menggunakan pesan kesalahan yang ditentukan.

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

Parameter

reason
String

Alasan untuk mengakhiri instans alur kerja.

Contoh

Contoh berikut meng-hosting alur kerja menggunakan WorkflowApplication. WorkflowApplication Instans dibangun menggunakan definisi alur kerja yang ditentukan, peristiwa siklus hidup alur kerja yang diinginkan ditangani, dan alur kerja dipanggil dengan panggilan ke Run. Setelah alur kerja dimulai, Terminate dipanggil. Saat alur kerja dihentikan, output berikut ditampilkan ke konsol.

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

Keterangan

Metode ini menjadwalkan penghentian instans alur kerja. Untuk diberi tahu ketika penghentian telah selesai, gunakan Completed handel.

Secara default, Terminate operasi harus selesai dalam 30 detik atau dilemparkan TimeoutException .

Berlaku untuk

Terminate(Exception, TimeSpan)

Mengakhiri instans alur kerja menggunakan pengecualian dan interval waktu habis yang ditentukan.

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)

Parameter

reason
Exception

Alasan untuk mengakhiri instans alur kerja.

timeout
TimeSpan

Interval di Terminate(Exception, TimeSpan) mana operasi harus selesai sebelum operasi dibatalkan dan TimeoutException dilemparkan.

Contoh

Contoh berikut meng-hosting alur kerja menggunakan WorkflowApplication. WorkflowApplication Instans dibangun menggunakan definisi alur kerja yang ditentukan, peristiwa siklus hidup alur kerja yang diinginkan ditangani, dan alur kerja dipanggil dengan panggilan ke Run. Setelah alur kerja dimulai, Terminate dipanggil. Saat alur kerja dihentikan, output berikut ditampilkan ke konsol.

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

Keterangan

Metode ini menjadwalkan penghentian alur kerja. Untuk diberi tahu ketika penghentian telah selesai, gunakan Completed handel.

Berlaku untuk

Terminate(String, TimeSpan)

Mengakhiri instans alur kerja menggunakan pesan kesalahan dan interval waktu habis yang ditentukan.

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)

Parameter

reason
String

Alasan untuk mengakhiri instans alur kerja.

timeout
TimeSpan

Interval di Terminate(String, TimeSpan) mana operasi harus selesai sebelum operasi dibatalkan dan TimeoutException dilemparkan.

Contoh

Contoh berikut meng-hosting alur kerja menggunakan WorkflowApplication. WorkflowApplication Instans dibangun menggunakan definisi alur kerja yang ditentukan, peristiwa siklus hidup alur kerja yang diinginkan ditangani, dan alur kerja dipanggil dengan panggilan ke Run. Setelah alur kerja dimulai, Terminate dipanggil. Saat alur kerja dihentikan, output berikut ditampilkan ke konsol.

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

Keterangan

Metode ini menjadwalkan penghentian instans alur kerja. Untuk diberi tahu ketika penghentian telah selesai, gunakan Completed handel.

Berlaku untuk