简单的WF顺序流
刚学习WF的一个DEMO很简单,对入门也应该很有作用吧。能够表现工作流的各种状态。希望对刚入门的Coder有所帮助吧。

(简单的顺序流流程图)

(简单的顺序流流程图)
Program.cs
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
using System.Workflow.Runtime.Hosting;
8
9
namespace 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
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
using System.Workflow.Runtime.Hosting;8

9
namespace WWFLife10
{11
class Program12
{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(工作流引擎代码)
1
using System;
2
using System.ComponentModel;
3
using System.ComponentModel.Design;
4
using System.Collections;
5
using System.Drawing;
6
using System.Reflection;
7
using System.Workflow.ComponentModel.Compiler;
8
using System.Workflow.ComponentModel.Serialization;
9
using System.Workflow.ComponentModel;
10
using System.Workflow.ComponentModel.Design;
11
using System.Workflow.Runtime;
12
using System.Workflow.Activities;
13
using System.Workflow.Activities.Rules;
14
15
namespace WWFLife
16
{
17
partial class Workflow1
18
{
19
Designer generated code
51
52
private SuspendActivity suspendActivity1;
53
private CodeActivity codeActivity1;
54
}
55
}
56
using System;2
using System.ComponentModel;3
using System.ComponentModel.Design;4
using System.Collections;5
using System.Drawing;6
using System.Reflection;7
using System.Workflow.ComponentModel.Compiler;8
using System.Workflow.ComponentModel.Serialization;9
using System.Workflow.ComponentModel;10
using System.Workflow.ComponentModel.Design;11
using System.Workflow.Runtime;12
using System.Workflow.Activities;13
using System.Workflow.Activities.Rules;14

15
namespace WWFLife16
{17
partial class Workflow118
{19
Designer generated code51

52
private SuspendActivity suspendActivity1;53
private CodeActivity codeActivity1;54
}55
}56




浙公网安备 33010602011771号