在一个系统推荐只有一个工作流引擎(当然也可以有多个)方便管理工作流实例,下面是单态模式的工作流工厂类文件。比较简单就不一一说明了
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Tracking;
using System.Configuration;
namespace ConsoleApplicationForWWF
{
public static class WorkflowFactory
{
private static WorkflowRuntime wfr = null;
private static object sys = new object();//同步锁对象
public static WorkflowRuntime GetWorkflowRuntime()
{
lock (sys)
{
if (wfr == null)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkflowRuntime);
wfr = new WorkflowRuntime();
}
return wfr;
}
}
static void StopWorkflowRuntime(object sender, EventArgs e)
{
if (wfr != null)
{
if (wfr.IsStarted)
{
try
{
wfr.StopRuntime();
}
catch (ObjectDisposedException e2)
{
Console.WriteLine("Error ! the workflowruntime is not disposed :" + e2.ToString());
}
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Tracking;
using System.Configuration;
namespace ConsoleApplicationForWWF
{
public static class WorkflowFactory
{
private static WorkflowRuntime wfr = null;
private static object sys = new object();//同步锁对象
public static WorkflowRuntime GetWorkflowRuntime()
{
lock (sys)
{
if (wfr == null)
{
AppDomain.CurrentDomain.ProcessExit += new EventHandler(StopWorkflowRuntime);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(StopWorkflowRuntime);
wfr = new WorkflowRuntime();
}
return wfr;
}
}
static void StopWorkflowRuntime(object sender, EventArgs e)
{
if (wfr != null)
{
if (wfr.IsStarted)
{
try
{
wfr.StopRuntime();
}
catch (ObjectDisposedException e2)
{
Console.WriteLine("Error ! the workflowruntime is not disposed :" + e2.ToString());
}
}
}
}
}
}
本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。