我现在工作流已经做好了“MainSignWorkFlow”,但是开始工作流的时候需要先启动工作流运行InitializeWorkflowRuntime(),这个启动只需要一次就好了,我把这个动作做成一个DLL供WEBSERVICE调用,这样的话,我次调用DLL处理工作流的时候都需要执行InitializeWorkflowRuntime()这个动作,这样的话速度上会慢,而且也是在重复的动作;
我现在想寻找一个办法,只要在服务器也就是WEBSERVICE端只启动一次InitializeWorkflowRuntime()就好了,当再有新的数据近来需要调用工作流的时候,检查是否已经启动了工作流运行,启动了就直接我代码中的处理签核业务。
不知道各位大侠有什么办法不,或者直接把这些动作移动到WEBSERVICE中也行,反正不要老重复启动_workflowRuntime = new WorkflowRuntime()这个动作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;
using System.Threading;
namespace EformWorkflow.ServerClass
{
public class InterfaceClass
{
private WorkflowRuntime _workflowRuntime;
private AutoResetEvent _waitHandle = new AutoResetEvent(false);
private string _ticket = string.Empty;
private int _FlowTableId = 0;
private int _Signal = 0;
private int _IfContinue = 0;
private int _IfPush = 0;
private int _Status = 0;
private int _SignStaffId = 0;
private string _SignMeaning = string.Empty;
private Byte[] _signMeaningImage;
private bool _SignResult;
// 启动工作流运行
private void InitializeWorkflowRuntime()
{
_workflowRuntime = new WorkflowRuntime();
//工作流完成后发生的事件
_workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
_SignResult = Convert.ToBoolean(e.OutputParameters["SignResult"]);
_waitHandle.Set();
};
//工作流终止后发生的事件
_workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
//MessageBox.Show(string.Format("工作流中断: {0}", e.Exception.Message), "工作流错误");
_SignResult = false;
_waitHandle.Set();
};
} //处理签核业务
public bool Do_MainFlow(string ticket, int FlowTableId, int Signal, int IfContinue, int IfPush, int Status, int SignStaffId,
string SignMeaning, Byte[] signMeaningImage)
{
//启动工作流运行时,每个应用程序域只能进行一次
InitializeWorkflowRuntime();
try
{
_ticket = ticket;
_FlowTableId = FlowTableId;
_Signal = Signal;
_IfContinue = IfContinue;
_IfPush = IfPush;
_Status = Status;
_SignStaffId = SignStaffId;
_SignMeaning = SignMeaning;
_signMeaningImage = signMeaningImage;
// 创建一个带有输入参数的字典
Dictionary<string, object> wfArguments = new Dictionary<string, object>();
wfArguments.Add("ticket", _ticket);
wfArguments.Add("FlowTableId", _FlowTableId);
wfArguments.Add("Signal", _Signal);
wfArguments.Add("IfContinue", _IfContinue);
wfArguments.Add("IfPush", _IfPush);
wfArguments.Add("Status", _Status);
wfArguments.Add("SignStaffId", _SignStaffId);
wfArguments.Add("SignMeaning", _SignMeaning);
wfArguments.Add("signMeaningImage", _signMeaningImage);
// 申请一个工作流实例并启动它
WorkflowInstance instance = _workflowRuntime.CreateWorkflow(typeof(EformWorkflow.WorkFolw.MainSignWorkFlow), wfArguments);
// 工作流开始
instance.Start();
// 等待处理完成
_waitHandle.WaitOne();
// 返回结果
return _SignResult;
}
catch
{
return false;
}
}
}
}
我现在想寻找一个办法,只要在服务器也就是WEBSERVICE端只启动一次InitializeWorkflowRuntime()就好了,当再有新的数据近来需要调用工作流的时候,检查是否已经启动了工作流运行,启动了就直接我代码中的处理签核业务。
不知道各位大侠有什么办法不,或者直接把这些动作移动到WEBSERVICE中也行,反正不要老重复启动_workflowRuntime = new WorkflowRuntime()这个动作。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Workflow.Runtime;
using System.Threading;
namespace EformWorkflow.ServerClass
{
public class InterfaceClass
{
private WorkflowRuntime _workflowRuntime;
private AutoResetEvent _waitHandle = new AutoResetEvent(false);
private string _ticket = string.Empty;
private int _FlowTableId = 0;
private int _Signal = 0;
private int _IfContinue = 0;
private int _IfPush = 0;
private int _Status = 0;
private int _SignStaffId = 0;
private string _SignMeaning = string.Empty;
private Byte[] _signMeaningImage;
private bool _SignResult;
// 启动工作流运行
private void InitializeWorkflowRuntime()
{
_workflowRuntime = new WorkflowRuntime();
//工作流完成后发生的事件
_workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
_SignResult = Convert.ToBoolean(e.OutputParameters["SignResult"]);
_waitHandle.Set();
};
//工作流终止后发生的事件
_workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
//MessageBox.Show(string.Format("工作流中断: {0}", e.Exception.Message), "工作流错误");
_SignResult = false;
_waitHandle.Set();
};
} //处理签核业务
public bool Do_MainFlow(string ticket, int FlowTableId, int Signal, int IfContinue, int IfPush, int Status, int SignStaffId,
string SignMeaning, Byte[] signMeaningImage)
{
//启动工作流运行时,每个应用程序域只能进行一次
InitializeWorkflowRuntime();
try
{
_ticket = ticket;
_FlowTableId = FlowTableId;
_Signal = Signal;
_IfContinue = IfContinue;
_IfPush = IfPush;
_Status = Status;
_SignStaffId = SignStaffId;
_SignMeaning = SignMeaning;
_signMeaningImage = signMeaningImage;
// 创建一个带有输入参数的字典
Dictionary<string, object> wfArguments = new Dictionary<string, object>();
wfArguments.Add("ticket", _ticket);
wfArguments.Add("FlowTableId", _FlowTableId);
wfArguments.Add("Signal", _Signal);
wfArguments.Add("IfContinue", _IfContinue);
wfArguments.Add("IfPush", _IfPush);
wfArguments.Add("Status", _Status);
wfArguments.Add("SignStaffId", _SignStaffId);
wfArguments.Add("SignMeaning", _SignMeaning);
wfArguments.Add("signMeaningImage", _signMeaningImage);
// 申请一个工作流实例并启动它
WorkflowInstance instance = _workflowRuntime.CreateWorkflow(typeof(EformWorkflow.WorkFolw.MainSignWorkFlow), wfArguments);
// 工作流开始
instance.Start();
// 等待处理完成
_waitHandle.WaitOne();
// 返回结果
return _SignResult;
}
catch
{
return false;
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货