# Tuesday, February 22, 2011

A workflow is a set of related activities. The relationship between these activities can take many forms.

Activity 3 may take place immediately after Activity 2.

Or Activity 6 some condition that is tested in Activity 7 and determines whether Activity 8a or 8b executes next.

Or Activity 9 may test a condition and repeat Activities 6-8 until the condition is false.

Below is a diagram representing a simple workflow that you may have written in a general purpose programming language, such as C# or Visual Basic. You may even have drawn a flowchart similar to this, either to assist in designing the program or to help document the program’s logic after it was written.

Figure 1

General purpose languages work very well for these simple workflows, as you can use constructs such as if statements and while loops to construct the program and assemble the activities.

But workflows can contain activities with more complex relationships and this complexity can make it difficult to write these workflows in a general purpose language.

Figure 2

In the workflow of Figure 2, four tasks are executed in parallel. For our purposes, parallel simply means that it doesn’t matter in which order each task begins or ends – it only matters that all 4 of them must complete before the workflow continues to the next activity.

This relationship can be complicated further if the workflow demands that only one of these activities complete before proceeding or if any 3 of the 4 activities complete. These scenarios would be difficult to write in procedural code. Doing so requires tracking global variables and a way to cancel activities that started and no longer need to complete.

Another complication occurs when a workflow requires external input at a step in he middle. Imagine a scenario in which an e-mail is sent to a manager. The e-mail contains a link to a web page. The manager clicks the link, reviews information on the web page and clicks a button to allow the workflow to continue to the next activity. The manager may click this button shortly after the e-mail is sent; or he may wait hours, days, or even weeks before clicking it. He may never click the button and our workflow should be able to handle this possibility (possibly by invoking a different activity after a specified timeout period). It is not scalable for a workflow to remain in memory for days or weeks, waiting for input. The practical solution is to serialize the state of the workflow and save it to a persistent data store; then de-serialize it and reload it into memory when the input finally arrives. If multiple copies of the same workflow are in progress, it’s also important that the correct instance is loaded into memory. When the manager clicks the button, some piece of data must tell the workflow which instance to retrieve.

A workflow framework can help to manage these complex relationships between workflow activities. Allowing a framework to manage these relationships also tends to keep the business activity code (the code executed by each activity) separate from the workflow code (the code that manages relationships between the activities.) This makes for a simpler and more maintainable code base.

Microsoft Windows Workflow Foundation (WF) is a framework designed to help you create and manage workflows.

You could write such a framework yourself, but why do that if this would be a lot of work and frameworks already exist to manage this for you?

WF provides a graphical user interface to design workflows by dragging a dozens of built-in activities from the Visual Studio toolbox onto a design surface. WF provides a rich API for building workflows and custom activities.

By hosting a workflow in IIS, you can accept incoming requests as web services or other WCF services; by utilizing WF’s integration with SQL Server, you can persist a workflow to a database and allow it to be retrieved at a later time; by using the built-in activities that ship with WF, you can simplify some of the programming tasks you need; and by creating a workflow with the graphical Workflow Designer in Visual Studio, you can more easily visualize the relationship between each step.

WF takes care of much of the workflow infrastructure for you and makes it easier to separate the internal activity logic from the workflow logic.

Tuesday, February 22, 2011 2:00:00 PM (GMT Standard Time, UTC+00:00)
Tuesday, October 11, 2011 8:06:45 AM (GMT Daylight Time, UTC+01:00)
Tuesday, December 20, 2011 3:44:45 AM (GMT Standard Time, UTC+00:00)
That's more than senisble! That's a great post!
Wednesday, December 21, 2011 10:48:53 AM (GMT Standard Time, UTC+00:00)
cpKasy , [url=http://kljlkltqscmj.com/]kljlkltqscmj[/url], [link=http://shatwshnnnno.com/]shatwshnnnno[/link], http://fouywrcgtesm.com/
Friday, December 23, 2011 5:07:57 PM (GMT Standard Time, UTC+00:00)
kMnTYS , [url=http://libcyjtnqgwa.com/]libcyjtnqgwa[/url], [link=http://lfpahbjisfan.com/]lfpahbjisfan[/link], http://bywkgakfwbiw.com/
Comments are closed.