This article contains the world�s�m �Essential Windows Workflow Foundation��s take a moment to grasp the general ideas behind WF. WF stands for Windows Workflow Foundation. It is a subsystem of the .NET Framework 3.0 which provides a runtime for creating and executing workflow-based applications. That�s nice marketing babble, but what exactly does that mean? Good question��s�t mean that just the data manipulated by the application is saved; I mean that the �program� itself is saved.
The state of the application is effectively �frozen� and put into a cryogenic freezer, so to speak. When it comes time to resume the workflow processing (i.e. the external stimulus arrives) the �frozen��s all of the introductory material I�m going to provide on WF. I didn�t explain nearly all of what WF is all about. If you are interested in a more thorough and circumspect explanation of WF, I recommend you read the book mentioned previously (�Essential Windows Workflow Foundation�). Now let�s play with some WF code!
The application I�m going to present to you here asks the user for his/her name, waits for the user to type it in, and then prints �Hello, UserName!� to the console. Obviously this application is only of interest because it uses Windows Workflow Foundation to perform its magic. I tried to keep the use of WF as simple and minimal as possible, just so that it�s easy to see how one goes about setting up an application which uses WF.
There are two assemblies involved in this application:
Each of the two assemblies contains two pieces of the puzzle:
FirstWFLibrary.DLL
Activitybase class and override its protected
Executemethod to provide their own execution logic.
FirstWFApp.EXE
EntryPointclass in this application takes care of that job.�s.
You might be wondering why an activity would return from the
Execute method if it was not done executing. Remember earlier on I mentioned that WF workflows can be �passivated� and stored in a database until it needs to continue executing? Well, an activity�s
Execute method will return
ActivityExecutionStatus.Executing if it cannot complete until external input eventually arrives.
In fact, the next step of The World�s�re not doing that here, but this next activity shows how to set up a �bookmark��s
Execute method a �bookmark� is established and the method immediately returns control back to the WF runtime. However, it returns �
Executing� to let the WF runtime know that it should not go on processing any other activities yet. When the user input finally arrives, the
ReadConsoleLine�s
ProcessQueueItemAvailable and
CloseActivity event handling methods will be invoked. The first of those methods stores the user�s name in a private variable. The other method cleans up and closes the activity, so that the WF runtime can continue processing other activities.�ll get to that soon, but now let�s see the
GreetUser activity.
/// �s�s.
The root activity contains the XML namespace mappings. The default XML namespace is mapped to the URI specified in the
XmlnsDefinition attribute in the previous section of the article. That allows us to refer to our custom activity types without any namespace prefix.�s�m not going to explain that method line by line, because it is commented well enough. The one point of interest I will mention is that once the
WorkflowInstance starts, the method then calls
Console.ReadLine to get the user�s name. Once the name is retrieved, it is put onto the �getUserName� workflow queue, which was created by and for the
ReadConsoleLine activity. This is an example of external input being provided to the workflow, causing it to resume processing. Once the user�s name is put onto the workflow queue, the
ReadConsoleLine activity will have its callback methods invoked so that it can finish executing.
This article showed how to create an application which uses Windows Workflow Foundation. Hopefully it left you feeling like The World�s �bookmarks��s scalability and performance.
General
News
Question
Answer
Joke
Rant
Admin