ManualWorkflowSchedulerService 手动调度服务.docx
- 文档编号:26698401
- 上传时间:2023-06-21
- 格式:DOCX
- 页数:10
- 大小:56.52KB
ManualWorkflowSchedulerService 手动调度服务.docx
《ManualWorkflowSchedulerService 手动调度服务.docx》由会员分享,可在线阅读,更多相关《ManualWorkflowSchedulerService 手动调度服务.docx(10页珍藏版)》请在冰豆网上搜索。
ManualWorkflowSchedulerService手动调度服务
1ManualWorkflowSchedulerService手动调度服务
当该服务加载到引擎中后,有如下特点:
1.如果实例正在运行,宿主的当前进程将被阻塞,直到工作流实例进入idle状态,引擎对宿主的阻塞才结束
2.对实例的操作,如启动(Start)、触发外部事件(handleExternalEventActivity)等操作,只以手动调用ManualWorkflowSchedulerService服务的RunWorkflow(实例ID)方法,才会真正执行
3.只有调用ManualWorkflowSchedulerService服务的RunWorkflow(实例ID)方法时,流程才运行,宿主才被阻塞
4.当实例进入idle状态时组塞才结束
5.可以依次调用完所用的触发外部事件(handleExternalEventActivity),再调用ManualWorkflowSchedulerService服务的RunWorkflow(实例ID)方法开始执行
ManualWorkflowSchedulerServicemws;
WorkflowRuntimeruntime;
runtime=newWorkflowRuntime();
mws=newManualWorkflowSchedulerService();
runtime.AddService(mws);
WorkflowInstanceinstance=runtime.CreateWorkflow(typeof(Workflow1));
GuidinstanceId;
instanceId=instance.InstanceId;
instance.Start();//此时,实例并没开始
mws.RunWorkflow(instanceId);//实例开始
2与正常的工作流对比说明
2.1外部事件
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Workflow.Activities;
namespacewxwinter.wf.TestWorkflow
{
[ExternalDataExchange]
publicinterfaceIEXService
{
eventEventHandler
eventEventHandler
eventEventHandler
}
[Serializable]
publicclassExService:
IEXService
{
publiceventEventHandler
publiceventEventHandler
publiceventEventHandler
publicvoidRone(GuidinstanceId)
{
if(this.one!
=null)
{
this.one(this,newExtEventArgs(instanceId));
}
}
publicvoidRtow(GuidinstanceId)
{
if(this.tow!
=null)
{
this.tow(this,newExtEventArgs(instanceId));
}
}
publicvoidRthree(GuidinstanceId)
{
if(this.three!
=null)
{
this.three(this,newExtEventArgs(instanceId));
}
}
}
[Serializable]
publicclassExtEventArgs:
ExternalDataEventArgs
{
publicExtEventArgs(GuidinstanceId)
:
base(instanceId)
{
}
}
}
2.2工作流
2.3工作流结点代码
usingSystem;
usingSystem.ComponentModel;
usingSystem.ComponentModel.Design;
usingSystem.Collections;
usingSystem.Drawing;
usingSystem.Workflow.ComponentModel.Compiler;
usingSystem.Workflow.ComponentModel.Serialization;
usingSystem.Workflow.ComponentModel;
usingSystem.Workflow.ComponentModel.Design;
usingSystem.Workflow.Runtime;
usingSystem.Workflow.Activities;
usingSystem.Workflow.Activities.Rules;
namespacewxwinter.wf.TestWorkflow
{
publicsealedpartialclassWorkflow1:
SequentialWorkflowActivity
{
publicWorkflow1()
{
InitializeComponent();
}
privatevoidcodeActivity1_ExecuteCode(objectsender,EventArgse)
{
System.Console.WriteLine("开始"+DateTime.Now.ToString());
}
privatevoidcodeActivity2_ExecuteCode(objectsender,EventArgse)
{
System.Console.WriteLine("One(随后sleep20M)"+DateTime.Now.ToString());
System.Threading.Thread.Sleep(20000);
}
privatevoidcodeActivity3_ExecuteCode(objectsender,EventArgse)
{
System.Console.WriteLine("two"+DateTime.Now.ToString());
}
privatevoidcodeActivity4_ExecuteCode(objectsender,EventArgse)
{
System.Console.WriteLine("three"+DateTime.Now.ToString());
}
}
}
2.4宿主代码
GuidinstanceId;
WorkflowRuntimeruntime;
ExServiceexchangeServer;
ManualWorkflowSchedulerServicemws;
//正常启动引擎
privatevoidbutton1_Click(objectsender,EventArgse)
{
runtime=newWorkflowRuntime();
ExternalDataExchangeServiceexchange=newExternalDataExchangeService();
runtime.AddService(exchange);
exchangeServer=newExService();
exchange.AddService(exchangeServer);
runtime.StartRuntime();
WorkflowInstanceinstance=runtime.CreateWorkflow(typeof(Workflow1));
instanceId=instance.InstanceId;
instance.Start();
}
//ManualWorkflowSchedulerService方式启动引擎
privatevoidbutton5_Click(objectsender,EventArgse)
{
runtime=newWorkflowRuntime();
ExternalDataExchangeServiceexchange=newExternalDataExchangeService();
runtime.AddService(exchange);
mws=newManualWorkflowSchedulerService();
runtime.AddService(mws);
exchangeServer=newExService();
exchange.AddService(exchangeServer);
runtime.StartRuntime();
WorkflowInstanceinstance=runtime.CreateWorkflow(typeof(Workflow1));
instanceId=instance.InstanceId;
instance.Start();
}
//one
privatevoidbutton2_Click(objectsender,EventArgse)
{
exchangeServer.Rone(instanceId);
}
//tow
privatevoidbutton3_Click(objectsender,EventArgse)
{
exchangeServer.Rtow(instanceId);
}
//three
privatevoidbutton4_Click(objectsender,EventArgse)
{
exchangeServer.Rthree(instanceId);
}
//ManualWorkflowSchedulerService的RunWorkflow
privatevoidbutton6_Click(objectsender,EventArgse)
{
mws.RunWorkflow(instanceId);
}
2.5正常使用
开始-09-1214:
33:
35
One(随后sleep20M)2007-09-1214:
33:
38
two2007-09-1214:
34:
05
three2007-09-1214:
34:
14
1.启动,开运行codeActivity1的代码,显示"开始-09-1214:
33:
35",然后进入one的idel
2.触发one,并运行codeActivity2的代码,,显示"One(随后sleep20M)2007-09-1214:
33:
38",Sleep20秒后,进入two的idel
3.触发two,并运行codeActivity3的代码,,显示"two2007-09-1214:
34:
05",进入three的idel
4.触发three,并运行codeActivity4的代码,,显示"three2007-09-1214:
34:
14",进入three的idel
注意:
A.当执行codeActivity2的Sleep20秒的过程中,宿主线程并没有被阻塞。
可以继承点击其他按钮
B.可以不等codeActivity2的Sleep20秒的过程结束,就可以直接点击后面的按钮,触发tow与three,此时,这些执行将在实例里排队,最后都会被依次执行
开始-09-1214:
39:
22
线程0x954已退出,返回值为0(0x0)。
线程0x1b0已退出,返回值为0(0x0)。
two2007-09-1214:
39:
42
three2007-09-1214:
39:
42
由于是排队,codeActivity3与codeActivity4,的执行,几乎没有时间差
2.6使用ManualWorkflowSchedulerService
开始2007-09-1214:
43:
13
One(随后sleep20M)2007-09-1214:
43:
13
two2007-09-1214:
43:
38
three2007-09-1214:
43:
40
操作过程是
1,run(启动->codeActivity1->oneidel)
2,run(触发one->codeActivity2->twoidel)
3,run(触发two->codeActivity3->threeidel)
4,run(触发three->codeActivity4->完成)
当实例没有进入idel时,宿组线程是被阻塞的,这时无法操作任何按钮,程序也进入一种无响应状态
注意:
A.对实例的所有操作只有执行ManualWorkflowSchedulerService服务的RunWorkflow(实例ID)方法时,才会直正被执行
B.可以是1,2,3,4,run的方式执行,也就是将所有对实例的操作都点击完后,再调用一次ManualWorkflowSchedulerService服务的RunWorkflow(实例ID)方法,就能完成全部操作
2.7在ASP.NET中的效果
正常情况下,页面提交操作后,不管理实例在引擎中的执行情况如何,页面都结束返回流
使用ManualWorkflowSchedulerService时,页面提交操作后,将处于等待状态,直到实例在引擎中进入idel状态,页面才结束返回流
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ManualWorkflowSchedulerService 手动调度服务 手动 调度 服务