Create a WF4.0 Project
1. Open VS2010, [File], [New], [Project]
2. In the [installed Templates] Tree of the [New Project] dialog box that appears [Workflow], select the [Workflow Console application] Item in the Template list box that appears
Enter [Helloworkflow] in the [Name] box and click [OK] to enter the design interface of the WF4.0 project.
Create a workflow for the output of a "Hello wxwinter" screen
Press [F5] to run the process, you will see the following results
Program Structure Description
This example includes two parts, a XAML file that describes the process structure, and a host program that invokes the process
XAML Process Structure Description file
The WF4.0 process structure description file is an XML-formatted file with the following format
(the XAML file format for WF4.0, which is described in a later article, is a basic explanation here)
<activity X:class= "Helloworkflow.workflow1" .... > <writeline text= "Hello Wxwinter" .... /> </Activity> |
WF4.0 processes are made up of a set of [activities], and when the process runs, the [activity] in the process executes according to certain rules
Where <Activity> </Activity> is the root of the process [activity]
<writeline/> is a self-bringing [activity] of WF4.0, whose function is to print the contents of the [Text property] on the screen
X:class= "Helloworkflow.workflow1" is the class name that corresponds to compiling the xoml file into a net class
Host Program
When created using the [Workflow Console application] template, a console host program for the test process is automatically created, as follows
Class Program { static void Main (string[] args) { Workflowinvoker.invoke (New Workflow1 ()); } } |
where [Workflowinvoker] is a function class for invoking a workflow, you can invoke the process using the Invoke static method of the class. In this case [Invoke (New Workflow1 ())] The class used is the xoml file x:class= " Helloworkflow.workflow1 "The class name defined by
Code mode create WF4.0 workflow
Class Program { static void Main (string[] args) { Workflowinvoker.invoke (Codecreateworkflow ()); } Code mode create WF4.0 workflow Static Activity Codecreateworkflow () { WriteLine writelineactivity = new WriteLine () {Text = "Hello Wxwinter"}; Sequence Wxwinterworkflow = new Sequence (); WXWINTERWORKFLOW.ACTIVITIES.ADD (writelineactivity); return wxwinterworkflow; } } |
Press [F5] to run the process, you will see the following results
WF4.0 Basic article (i) Start using wf--Next Chapter