一、打开vs2008----添加新项目---顺序工作流控制台应用程序
二、在工具箱中找到IfElse。将它拖入到我们的设计界面上。
三、选择“ifElseBranchActivity1”---“属性”---选择Condition下拉列表中的“代码条件”,再输入处理事件的名称“isok”。回车,VS会自动的生成处理代码。
private string str;
public string Str
{
get { return str; }
set { str = value; }
}
private void isok(object sender, ConditionalEventArgs e)
{
if (Str == "aa")
e.Result = true;
else
e.Result = false;
}
四、创建分支的处理程序。现在我们返回设计界面。向左右的分支拖入Code控件。
选择“codeActivity1”--属性ExecuteCode中输入“istrue”,回车,
private void istrue(object sender, EventArgs e)
{
Console.WriteLine("is ok!");
}
选择“codeActivity2”--属性ExecuteCode中输入“isfalse”,回车,
private void isfalse(object sender, EventArgs e)
{
Console.WriteLine("is not ok!");
}
五、至此。我们的workflow代码编写完毕。现在我们需要稍稍的修改下我们的Program.cs文件。打开Program.cs文件。找到
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof...
在其上面插入以下代码用作传递参数到workflow中。
using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {waitHandle.Set();};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
Console.WriteLine("enter a word:");
string str = Console.ReadLine();
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("Str", str);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(WorkflowConsoleTest1.Workflow1), dic);
instance.Start();
waitHandle.WaitOne();
Console.ReadLine();
}