The following WF console application (written in C#) will 1) pause for 5 seconds, 2) write the line "Hello," 3) pause another 5 seconds, and then 4) write the line "World!" I know, not terribly practical, but it will get you familiar with creating WF v4 applications for the first time, assuming you'r new to this, that is.
- Open up Visual Studio 2010.
- Press Ctrl-Shift-N to create a new project.
- In the 'Installed Templates' pane, select 'Workflow'.
- Select the 'Workflow Console Application' template.
- Name the project DotNetFun.Workflow.HelloWorld.
- Click on OK.
- Ensure that the 'Workflow1.xaml' file is open.
- Drag a 'Sequence' from the toolbox's 'Control Flow' section onto the area of the designer labeled 'Drop activity here'.
- Click on the sequence to select it.
- At the bottom of the designer, click on the 'Variable' tab button.
- Click on where it says 'Create Variable'.
- Type pauseWaitTime. This will be the variable that stores how long each pause will be.
- In the 'Variable type' column, select 'Browse for Types...', then in 'Type Name:' text box, type System.TimeSpan.
- Click on 'OK'.
- In the 'Default' column, type the following code expression: new TimeSpan(0,0,5)
The 'pauseWaitTime' variable will now be available within the 'Sequence' scope, available to the sequence and all of its child elements. - In the 'Primitives' section of the toolbox, drag a 'Delay' activity into the 'Sequence' sequence.
- In the properties explorer for the Delay activity, enter pauseWaitTime in the 'Duration' text box.
- In the properties explorer for the Delay activity, change the name to Delay1.
- In the 'Primitives' section of the toolbox, drag a 'WriteLine' activity directly beneath the 'Delay1' activity.
- Click on the 'Enter a VB expression' text box and enter "Hello," (with double quotes, as this is a string literal expression).
- In the properties explorer for the WriteLine activity, change the name to WriteLine1.
- In the 'Primitives' section of the toolbox, drag a 'Delay' directly beneath the 'WriteLine1' activity.
- In the properties explorer for the Delay activity, enter pauseWaitTime in the 'Duration' text box.
- In the properties explorer for the Delay activity, change the name to Delay2.
- In the 'Primitives' section of the toolbox, drag a 'WriteLine' activity directly beneath the 'Delay2' activity.
- Click on the 'Enter a VB expression' text box and enter "World!" (with double quotes, as this is a string literal expression).
- In the properties explorer for the WriteLine activity, change the name to WriteLine2. The workflow designer should now look like the following:
- Open the Program.cs class file.
- Add the following code after the WorkflowInvoker.Invoke method call:
Console.WriteLine("Press any key to exit..."); Console.ReadKey();
- Press F5 to run and test the workflow application.
That does it for this very simple introduction to WF v4 workflows. Be on the lookout for more!
No comments:
Post a Comment