一个简单的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,>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值