In my job I created workflow engine and many workflows based on it. I will not show you the engine I developed but I'd like to start set of articles on Windows Workflow Foundation - MS workflow engine. It's still in its beta version but it looks extremely interesting to me and I believe it should be point of main interest to many developers.
Let's start from real-live requirements that we will try to target in WWF:
- Create an Outlook task, passing some parameters to it (e.g. task subject).
- Wait for the created task to finish (end user checks the task in Outlook as completed)
How to achieve this:
- Create WWF 'Sequential Workflow Library' project. The project by default contains one custom activity which looks like this in VS designer:
- Change the activity name and its base type from CompositeActivity to Activity.
- Add a property to the activity that will hold the Outlook task subject. It can be added through the activity designer so you don't need to write anything.
- Write the activity logic in its Execute method. After this the CreateOutlookTask activity may look like this:
[ToolboxItemAttribute(typeof(ActivityToolboxItem))]
public partial class CreateOutlookTask : Activity
{
public static DependencyProperty SubjectProperty = DependencyProperty.Register(
"Subject", typeof(System.String), typeof(CreateOutlookTask));
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
[ValidationVisibilityAttribute(ValidationVisibility.Optional)]
[BrowsableAttribute(true)]
public string Subject
{
get { return ((string)(base.GetValue(Workflow.CreateOutlookTask.SubjectProperty))); }
set { base.SetValue(Workflow.CreateOutlookTask.SubjectProperty, value); }
}
protected override Status Execute(ActivityExecutionContext context)
{
Application outlook = new ApplicationClass();
TaskItem task = (TaskItem)outlook.CreateItem(OlItemType.olTaskItem);
task.Status = OlTaskStatus.olTaskNotStarted;
task.Subject = this.Subject;
task.Save();
return Status.Closed;
}
}
- Now we can add a Workflow to our project and to drop the OutlookTaskActivity on the designer surface. It will look like this:

- Set the task Subject property in VS designer (see above) and we are ready to run the Workflow.
- Let's run the Workflow:
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
workflowRuntime.StartRuntime();
workflowRuntime.StartWorkflow(typeof(OutlookWorkflow));
As a result of the above steps we receive an outlook task created from workflow. As you can see such things can be achieved in WWF easily (I believe it is very important to easily extend any workflow).
Next time I will show you how to create another activity that waits for the Outlook task to be completed and continues the workflow.