建立一個內含WWF的應用程式

转自:Jiade's Talk 的blog

首先,我們開啟VS.NET2005,建立一個新的Sequential WorkFlow專案,並利用WWF提供的Activity,建立如下的流程,分別於DOS模式下輸出"FIRST"及"SECOND"字眼…

其次我們就要撰寫這兩個Code節點中所要執行的動作,您可以切換到code view,新增以下的兩個function

private void code1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("FIRST");
}

private void code2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("SECOND");
}

分別執行兩個不同的節點動作…執行編譯動作,您就已經完成流程設計的動作。

接下來就是要撰寫一個應用程式去執行這一段流程:

1.一樣開始VS.NET2005,建立一個Console應用程式

2.將以下CLASS加入參考 System.Workflow.* 以及我們剛剛建立的DLL檔案

3.撰寫以下程式碼

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Reflection;



namespace ConsoleTest
{
class Program
{
static AutoResetEvent waitHandle = new AutoResetEvent(false);
static void Main(string[] args)
{
try
{
Console.WriteLine("Start Application");
WorkflowRuntime wfr = new WorkflowRuntime();
wfr.StartRuntime();
System.Type type = typeof(myWorkflow2.Workflow1);
wfr.WorkflowCompleted += OnWorkflowCompletion;
wfr.StartWorkflow(type);
waitHandle.WaitOne();
Console.WriteLine("Application End");
Console.ReadLine();
wfr.StopRuntime();
}
catch { }

}
static void OnWorkflowCompletion(object sender, WorkflowCompletedEventArgs instance)
{
waitHandle.Set();
}
}
}

4.執行該Console程式您將會看到程式依序輸入 "FIRST" 和 "SECOND"

您可以試著再度開啟剛剛的流程設計專案,將code1和Code2的順序對調,存檔後,在執行一次,則輸出的順序就變成"SECOND"和"FIRST"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值