Datasheet
Chapter 1: Workfl ow Programming Principles
10
Activity Uninitialization
If your custom activity overrides the Initialize method of the Activity base class, it must also override the
UnInitialize method to uninitialize itself. The UnIntialize method undoes what the Initialize method does.
For example, if the Initialize method creates and adds a new workflow queue to the workflow queuing
service, the UnInitialize method must remove the same workflow queue from the workflow queuing service.
Listing 1 - 3 shows a typical implementation of the Uninitialize method of a custom activity.
Listing 1 - 3: A typical implementation of the Uninitialize method
Using System;
using System.Workflow.ComponentModel;
using System.Workflow.Runtime;
namespace Chapter1
{
public class CustomActivity : Activity
{
. . .
protected override void Uninitialize(IServiceProvider provider)
{
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
if (workflowQueuingService.Exists(this.Name))
workflowQueuingService.DeleteWorkflowQueue(this.Name);
}
}
}
The Uninitialize method takes these steps to remove the workflow queue:
1. It accesses the WorkflowQueuingService service:
WorkflowQueuingService workflowQueuingService =
provider.GetService(typeof(WorkflowQueuingService))
as WorkflowQueuingService;
2. It checks whether the WorkflowQueuingService service contains the workflow queue with the
specified name. If so, it invokes the DeleteWorkflowQueue method on the
WorkflowQueuingService service to remove the workflow queue:
if (workflowQueuingService.Exists(this.Name))
workflowQueuingService.DeleteWorkflowQueue(this.Name);
Keep in mind that the Uninitialize method of an activity, just like its Initialize method, is invoked only
once during the lifetime of an activity, which could last an indefinitely long time and span multiple
thread, process, or machine boundaries.
c01.indd 10c01.indd 10 8/25/08 4:02:54 PM8/25/08 4:02:54 PM