1.建立一個WF 循序工作流程專案,MyFlow1:
2.從Toolbox將Code拉到流程設計畫面:
3.選取畫面上CodeActivity1,設ExecuteCode屬性為SayHi,進入事件處理常式
4.加入以下程式碼到事件處理常式
1 private void SayHi(object sender, EventArgs e)
2 {
3 Console.WriteLine("Hello");
4 }
5.在方案中加入一個新MyFlow2循序工作流程專案,到目前方案
6.重複3,4步驟,但步驟四個程式改為
1 private void SayHi(object sender, EventArgs e)
2 {
3 Console.WriteLine("World");
4 }
7.從Sloution Explorer,MyFlow1專案,按鼠右鍵,選加入參考,從專案頁,選取MyFlow2,參考MyFlow2專案
8.Build Solution
9.在MyFlow1設計畫面中,從Toolbox將InvokeWorkFlow拉到流程設計畫面CodeActivity1下
10.設定invokeWorkFlowActivity1的TargetWorkFlow屬性,選取MyFlow2.Workflow1
12.畫面看起來為:
13.在方案中加入一個新MyConHost主控台應用程式專案到目前方案,當作裝載主程式
14.在MyConHost專案加入參考
15.在MyConHost專案加入MyFlow1參考
16.在MyConHost專案加入以下組件參考
17.在MyConHost專案Program.cs加入以下程式碼,啟動MyFlow1.Workflow1流程
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 using System.Workflow.Runtime;
7 namespace MyConHost
8 {
9 class Program
10 {
11 private static AutoResetEvent waitHandle = new AutoResetEvent(false);
12 static WorkflowRuntime rt = null;
13 static WorkflowInstance inst = null;
14 static void Main(string[] args)
15 {
16 rt = new WorkflowRuntime();
17 rt.StartRuntime();
18 rt.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(rt_WorkflowCompleted);
19 rt.WorkflowTerminated += new EventHandler<WorkflowTerminatedEventArgs>(rt_WorkflowTerminated);
20 inst = rt.CreateWorkflow(typeof(MyFlow1.Workflow1));
21 inst.Start();
22 waitHandle.WaitOne();
23 }
24 static void rt_WorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
25 {
26 Console.WriteLine("WorkflowTerminated" + e.Exception.Message);
27 waitHandle.Set();
28 }
29 static void rt_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
30 {
31 Console.WriteLine("WorkflowCompleted");
32 waitHandle.Set();
33 }
34 }
35 }
18執行結果:
下載程式