简单的WF顺序流
刚学习WF的一个DEMO很简单,对入门也应该很有作用吧。能够表现工作流的各种状态。希望对刚入门的Coder有所帮助吧。
(简单的顺序流流程图)
(简单的顺序流流程图)
Program.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using System.Workflow.Runtime;
7using System.Workflow.Runtime.Hosting;
8
9namespace WWFLife
10{
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
16 {
17 AutoResetEvent waitHandle = new AutoResetEvent(false);
18 workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
19 {
20 waitHandle.Set();
21 Console.WriteLine("工作流实例化完成!");
22 };
23 workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
24 {
25 Console.WriteLine(e.Exception.Message);
26 Console.WriteLine("工作流终止!");
27 waitHandle.Set();
28 };
29 workflowRuntime.WorkflowCreated += delegate(object sender, WorkflowEventArgs e)
30 {
31 Console.WriteLine("工作流创建成功!");
32 };
33 workflowRuntime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)
34 {
35 Console.WriteLine("工作流开始!");
36 };
37 workflowRuntime.WorkflowSuspended += delegate(object sender, WorkflowSuspendedEventArgs e)
38 {
39 Console.WriteLine("工作流暂停!");
40
41 //输出SuspendActivty的Error属性内容
42 Console.WriteLine("\t原因: " + e.Error);
43
44 //让工作流恢复执行
45 e.WorkflowInstance.Resume();
46 };
47 workflowRuntime.WorkflowIdled += delegate(object sender, WorkflowEventArgs e)
48 {
49 Console.WriteLine("工作流空闲!");
50 };
51 workflowRuntime.WorkflowResumed += delegate(object sender, WorkflowEventArgs e)
52 {
53 Console.WriteLine("工作流恢复!");
54 waitHandle.Set();
55 };
56
57 WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WWFLife.Workflow1));
58 instance.Start();
59
60 waitHandle.WaitOne();
61 }
62 }
63 }
64}
65
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading;
6using System.Workflow.Runtime;
7using System.Workflow.Runtime.Hosting;
8
9namespace WWFLife
10{
11 class Program
12 {
13 static void Main(string[] args)
14 {
15 using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
16 {
17 AutoResetEvent waitHandle = new AutoResetEvent(false);
18 workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
19 {
20 waitHandle.Set();
21 Console.WriteLine("工作流实例化完成!");
22 };
23 workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
24 {
25 Console.WriteLine(e.Exception.Message);
26 Console.WriteLine("工作流终止!");
27 waitHandle.Set();
28 };
29 workflowRuntime.WorkflowCreated += delegate(object sender, WorkflowEventArgs e)
30 {
31 Console.WriteLine("工作流创建成功!");
32 };
33 workflowRuntime.WorkflowStarted += delegate(object sender, WorkflowEventArgs e)
34 {
35 Console.WriteLine("工作流开始!");
36 };
37 workflowRuntime.WorkflowSuspended += delegate(object sender, WorkflowSuspendedEventArgs e)
38 {
39 Console.WriteLine("工作流暂停!");
40
41 //输出SuspendActivty的Error属性内容
42 Console.WriteLine("\t原因: " + e.Error);
43
44 //让工作流恢复执行
45 e.WorkflowInstance.Resume();
46 };
47 workflowRuntime.WorkflowIdled += delegate(object sender, WorkflowEventArgs e)
48 {
49 Console.WriteLine("工作流空闲!");
50 };
51 workflowRuntime.WorkflowResumed += delegate(object sender, WorkflowEventArgs e)
52 {
53 Console.WriteLine("工作流恢复!");
54 waitHandle.Set();
55 };
56
57 WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WWFLife.Workflow1));
58 instance.Start();
59
60 waitHandle.WaitOne();
61 }
62 }
63 }
64}
65
Workflow1.cs(工作流引擎代码)
1using System;
2using System.ComponentModel;
3using System.ComponentModel.Design;
4using System.Collections;
5using System.Drawing;
6using System.Reflection;
7using System.Workflow.ComponentModel.Compiler;
8using System.Workflow.ComponentModel.Serialization;
9using System.Workflow.ComponentModel;
10using System.Workflow.ComponentModel.Design;
11using System.Workflow.Runtime;
12using System.Workflow.Activities;
13using System.Workflow.Activities.Rules;
14
15namespace WWFLife
16{
17 partial class Workflow1
18 {
19 Designer generated code
51
52 private SuspendActivity suspendActivity1;
53 private CodeActivity codeActivity1;
54 }
55}
56
2using System.ComponentModel;
3using System.ComponentModel.Design;
4using System.Collections;
5using System.Drawing;
6using System.Reflection;
7using System.Workflow.ComponentModel.Compiler;
8using System.Workflow.ComponentModel.Serialization;
9using System.Workflow.ComponentModel;
10using System.Workflow.ComponentModel.Design;
11using System.Workflow.Runtime;
12using System.Workflow.Activities;
13using System.Workflow.Activities.Rules;
14
15namespace WWFLife
16{
17 partial class Workflow1
18 {
19 Designer generated code
51
52 private SuspendActivity suspendActivity1;
53 private CodeActivity codeActivity1;
54 }
55}
56