Szerkesztés

Megosztás a következőn keresztül:


WorkflowApplication.Cancel Method

Definition

Cancels the workflow instance.

Overloads

Cancel()

Cancels the workflow instance.

Cancel(TimeSpan)

Cancels the workflow instance using the specified time-out interval.

Remarks

This method schedules the cancellation of the workflow instance. To be notified when the cancellation has completed, use the Completed handle.

By default, the cancel operation must complete in 30 seconds or a TimeoutException is thrown.

Cancel()

Cancels the workflow instance.

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

Examples

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, Cancel is called. When the workflow is cancelled, the following output is displayed to the console.

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

Remarks

This method schedules the cancellation of the workflow instance. To be notified when the cancellation has completed, use the Completed handler.

By default, the cancel operation must complete in 30 seconds or a TimeoutException is thrown.

Applies to

Cancel(TimeSpan)

Cancels the workflow instance using the specified time-out interval.

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

Parameters

timeout
TimeSpan

The interval in which the cancel operation must complete before the operation is canceled and a TimeoutException is thrown.

Examples

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, Cancel is called. When the workflow is cancelled, the following output is displayed to the console.

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

Remarks

This method schedules the cancellation of the workflow instance. To be notified when the cancellation has completed, use the Completed handler.

Applies to