`
ppenny
  • 浏览: 31552 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

一个简单的workflow程序

阅读更多
今天看电子书《Presenting Windows Workflow Foundation》因为是beta版的,所以和.Net Framework3.0有一定的差别,看到介绍Data activity的时候实在是忍不住了,干脆吧换另一本书看《Foundations of WF An Introduction to Windows Workflow Foundation》不过觉得对那本beta版的书“半途而废”还是值得的。
下面是书上的第一个console下的sequential workflow小程序:
Workflow1.cs代码如下:
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;
namespace CFirstSequentialWFConsoleApplicaton
{
public sealed partial class Workflow1: SequentialWorkflowActivity
{
private int InputValue1;
private int InputValue2;
private int OutputResult;
public int Input1
{
set { InputValue1 = value; }
}
public int Input2
{
set { InputValue2 = value; }
}
public int OutputValue
{
get { return OutputResult; }
}
public Workflow1()
{
InitializeComponent();
}
private void Step1_ExecuteCode(object sender, EventArgs e)
{
OutputResult = InputValue1 + InputValue2;
Console.WriteLine("Step1");
}
private void Step2_ExecutedCode(object sender, EventArgs e)
{
Console.WriteLine("Step2");
}
}
}
program.cs代码如下:
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
#endregion
namespace CFirstSequentialWFConsoleApplicaton
{
class Program
{
static void Main(string[] args)
{
AutoResetEvent waitHandle = new AutoResetEvent(false);
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
//AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
Dictionary<string,> parameters = new Dictionary<string,>();
parameters["Input1"] = 45;
parameters["Input2"] = 45;
WorkflowInstance instance= workflowRuntime.CreateWorkflow(typeof(CFirstSequentialWFConsoleApplicaton.Workflow1),parameters);
instance.Start();
waitHandle.WaitOne();
}
}
static void OnWorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
{
Console.WriteLine(e.OutputParameters["OutputValue"]);
}
static void OnWorkflowTerminated(object sender, WorkflowTerminatedEventArgs e)
{ }
}
}
在workflow的designer里drag两个code把两个code的ExecuteCode属性设置为上面program.cs中的Step1_ExecuteCode和Step2_ExecuteCode。运行debug即可看到console下的运行结果。</string,></string,>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics