Share via


WorkflowApplication.Cancel Metode

Definisi

Membatalkan instans alur kerja.

Overload

Cancel()

Membatalkan instans alur kerja.

Cancel(TimeSpan)

Membatalkan instans alur kerja menggunakan interval waktu habis yang ditentukan.

Keterangan

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

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

Cancel()

Membatalkan instans alur kerja.

public:
 void Cancel();
public void Cancel ();
member this.Cancel : unit -> unit
Public Sub Cancel ()

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, Cancel dipanggil. Saat alur kerja dibatalkan, output berikut ditampilkan ke konsol.

Starting the workflow.   
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac Idle.   
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac Canceled  
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac 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);
    }
};

// Run the workflow.
wfApp.Run();

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Cancel();

Keterangan

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

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

Berlaku untuk

Cancel(TimeSpan)

Membatalkan instans alur kerja menggunakan interval waktu habis yang ditentukan.

public:
 void Cancel(TimeSpan timeout);
public void Cancel (TimeSpan timeout);
member this.Cancel : TimeSpan -> unit
Public Sub Cancel (timeout As TimeSpan)

Parameter

timeout
TimeSpan

Interval di mana operasi pembatalan harus diselesaikan 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, Cancel dipanggil. Saat alur kerja dibatalkan, output berikut ditampilkan ke konsol.

Starting the workflow.   
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac Idle.   
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac Canceled  
Workflow bcce00c2-d323-42c2-8c25-19ff0c4b6dac 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);
    }
};

// Run the workflow.
wfApp.Run();

Thread.Sleep(TimeSpan.FromSeconds(1));

wfApp.Cancel();

Keterangan

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

Berlaku untuk