Page 1 of 2
Windows WorkFlow and Visual Basic.NET are natural companions. In this short introduction we cover just enough ground to get you started.
Making a fresh start
Windows WorkFlow or WF has always been listed along with WCF and WPF as one of the pillars of the .NET system, but it has always been the poor relation. Not all .NET programmers have seen the value in WF while WPF’s value is obvious and even the more complex WCF has its attractions.
What is important about the latest release of WF is that it is all new that any conclusions you might have reached about it are invalid. You need to forget about WF 3.5 and start over with WF 4.0. There is a certain amount of backward compatibility built into the new system in the sense that you can run WF 3.5 workflows, but you need to start afresh with the new system to get the best from it.
What is workflow?
First what is “workflow”? Although many purists would object to my take on the topic I think it's clear that WF is just another in the long line of attempts to reduce programming to diagramming.
Essentially WF provides a graphical way to define and create an algorithm. We are all familiar with the flow chart approach to defining what should happen and WF is at its heart a flowchart designer and compiler. So if you aren’t interested in graphical programming methods you can mostly ignore WF – but you might be surprised at how many different ways it can be used.
If you want to get started with WF 4.0 the simplest thing to do is to download the trial of Visual Studio 2010. You can use WF 4.0 from any .NET language but its natural companion is Visual Basic and this is the language used in the example.
A hands-on example
Download and install Visual Studio 2010 and start a new Visual Basic Workflow application and select Workflow Console Application. You will see that the generated project contains just two major files – Module1.vb which contains the WF code and Workflow1.xaml which contains the XAML that generates the workflow.
Looking at the blank workflow designer doesn’t give you much idea what to do next. A workflow is a sequence of activities and each activity can in itself be a sequence of activities. You can also create your own custom activities – more of which later. To get started, however, all we need to do is create a sequence of activities.
The first thing we need is a sequence activity which as its name suggests is a container for a set of activities which are executed one after another. Open the Toolbox, and from the Control Flow section drag and drop the Sequence activity onto the design surface.
You can see that the Sequence activity is ready to accept other activities.
Now open the Toolbox and from the Primitives section drag and drop a WriteLine activity into the Sequence activity. You can now enter “Hello WF World” into the field within the WriteLine activity.
Now if you run the project you will see a console window open, the message appears for a moment and then the project terminates.
To keep the message on the screen for 30 seconds drag and drop a Delay activity and enter 00:00:30 for its Duration using the Properties Window. Now when you run it the two activities are executed one after another with the result that the message remains visible for 30 seconds.