<一>在解决方案中,建立顺序工作流库,在流程设计器中将code 拖入,并双打击
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
//要添加引用哦
using System.Windows.Forms;
namespace WorkflowLibrary1
{
public sealed partial class Workflow1: SequentialWorkflowActivity //WWF Beta 2 继承的类库发生了变化
{
//在WWF Beta1 中,具有可视化设置code的Parameters;但在WWF Beta 2中已经取消了
private string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
private string lastName;
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public Workflow1()
{
InitializeComponent();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
MessageBox.Show("Welcome, " + firstName + " " + lastName); // 工作流节点code执行部分
}
}
}
<二>解决方案中,项目WindowsApplication1 的Form1.CS
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
//要在解决方案的项目中添加引用
using System.Workflow.Runtime;
using System.Workflow.ComponentModel;
using System.Workflow.Runtime.Hosting;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private WorkflowRuntime _wr = null;
private string _workflowassembly = "";
private string _workflowtypeName = "";
//构造函数
public Form1()
{
InitializeComponent();
_workflowassembly = "WorkflowLibrary1"; //工作流项目所在的命名空间
_workflowtypeName = "WorkflowLibrary1.Workflow1"; //类
_wr = new WorkflowRuntime(); //实例化类WorkRuntime
_wr.StartRuntime();
}
private void button1_Click(object sender, EventArgs e)
{
string assemblyname = _workflowassembly;
string typename = _workflowtypeName;
Assembly assembly = Assembly.Load(assemblyname); //装载
Type workflowtype = assembly.GetType(typename); //取得类Workflow1
Dictionary<string ,object> parameters = new Dictionary<string ,object>();
parameters.Add("FirstName", this.txtFirstName.Text); //添加参数
parameters.Add("LastName", this.txtLastName.Text);
//注意在WWF Beta1中,是用方法StarWorkflow()
WorkflowInstance instance = _wr.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1), parameters);
instance.Start(); //开启
}
}
}