CodeAndDelay。
雙擊 Code 活動進入 ExecuteCode 事件:
namespace CodeAndDelay
{
public sealed partial class Workflow1 : SequentialWorkflowActivity
{
public Workflow1() { InitializeComponent(); }
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("\n這裡是活動一的執行代碼,當前時間為{0}。", DateTime.Now);
}
private void codeActivity2_ExecuteCode(object sender, EventArgs e)
{
Console.WriteLine("\n這裡是活動二的執行代碼,當前時間為{0}。", DateTime.Now);
}
}
}
屬性視窗設定 TimeoutDuration = 00:00:05(5 秒)。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
namespace CodeAndDelay
{
class Program
{
static void Main(string[] args)
{
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();
};
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(CodeAndDelay.Workflow1));
instance.Start();
waitHandle.WaitOne();
}
}
}
}
活動一輸出時間 → 5 秒延遲 → 活動二輸出時間(相差 5 秒)。
MSDN 建議:DelayActivity 的 InitializeTimeoutDuration 事件不應用於設定 TimeoutDuration,應在 InitializeComponent 中設定。
https://zhuxianzhong.blog.51cto.com/157061/203300