看到网上普遍流传的一个WWF的入门示例(HelloWorld),个人感觉它只是让初学者在VS2005中跑起了一个WWF的小程序,但却没有让读者感受到Workflow的一丁点含义,我的这个入门示例是跟WorkFlow打招呼:
打招呼的两种形式(也可以说是流程吧,呵呵)
Hello Workflow
Workflow Hello
两种不同的打招乎的流程(仅公假设而已)
确保你机子上装了
VS2005
DOTNET3.0
Visual Studio 2005 Extensions for Windows Workflow Foundation (CHS)
打开VS2005,新建一个项目,选择Visual C#(当然也可以先VB)节点,再点击workflow,选择顺序工作流控制台应用程序,OK这样一个项目就建立好了.
双击workflow1.cs转到设计视图,从工具箱中分别将两个code activity拖到顺序工作流中,如下图所示:
Code表示执行的代码块,看到每个activity右上方都有代码块了吗?是因为我们还没有为它指定代码块,别急,我们这就来搞定它!
双击第一个codeActivity,自动转到代码中(这与我们在VB中的感觉一样吧),在光标处写上代码:
Console.Write("Hello ");
同样双击每二个codeActivity,写上代码:
Console.Write("Workflow ");
为了我们在运行程序时可以看到效果,打开Program.cs在Main方法块内,结尾加上
Console.ReadLine();
按F5,运行后如图:
问题又来了,当我们要表达Workflow Hello,该怎么办,改动方法体内部的代码,将
codeActivity1_ExecuteCode方法中
Console.Write("Hello ");换成Console.Write("Workflow ");
codeActivity2_ExecuteCode方法中
Console.Write("Workflow ");换成Console.Write("Hello ");
其实完全不用这样:
选中codeActivity1,在属性窗口中将ExecuteCode属性值选为codeActivity2_ExecuteCode
(在下拉列表中选取即可)
同样将codeActivity2的ExecuteCode属性值选为codeActivity1_ExecuteCode
OK,按F5,是不是出现了” Workflow Hello”.
从" Hello Workflow"到" Workflow Hello"的转变,只须轻点几下
希望这是一个好的开始.