这几天在研究Windows Workflow Foundation,天天上
www.windowsworkflow.net 的论坛上查看和询问,全都是英文,头都看大了,对这金山词霸一个一个的啃。闲话少说,步入正题吧!
本篇主要讲WF在asp.net运用。如下:
我的流程设置如下:
设置了一个CodeActive和一个HandleExternalEventActive
CodeActive是执行一段代码的Active
HandleExternalEventActive是外联一个Event的Active
首先,配置web.config
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="WorkflowRuntime" type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.ComponentModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
</system.web>
<!--注册服务-->
<WorkflowRuntime Name="WorkflowServiceContainer">
<Services>
<add type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Activities.ExternalDataExchangeService, System.Workflow.Activities, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add type="System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" UnloadOnIdle="true" ConnectionString="Initial Catalog=PersistenceStore;Data Source=localhost;Integrated Security=SSPI;"/>
<add type="System.Workflow.Runtime.Tracking.SqlTrackingService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" ConnectionString="Initial Catalog=TrackingStore;Data Source=localhost;Integrated Security=SSPI;"/>
</Services>
</WorkflowRuntime>
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
<!--设置追踪,会在网站根目录下出现WFTrace.log文件-->
<system.diagnostics>
<switches>
<add name="WorkflowTraceToDefault" value="1" />
<add name="Host" value="All" />
<add name="Runtime" value="All" />
<add name="Tracking" value="All" />
<add name="Activity" value="All" />
<add name="Rules" value="All" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="WFTrace.log" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
简单介绍上面的配置文件
a.注册服务
这里是将一些服务注册到 Workruntime中,你也可以在代码中使用AddServcie中注册服务。
注册好服务后,就可以在代码中
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
以上方式得到服务。
b.跟踪
配置跟踪信息,非常有用,我有一次调试的时候,MSDTC 服务没有启动的错误,就是查看WFTrace.log文件而获得的。
然后,在Global中启动一个WorkRunTime
void Application_Start(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime("WorkflowRuntime");
Application["WorkflowRuntime"] = workflowRuntime;
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
System.Workflow.ComponentModel.Compiler.TypeProvider typeProvider = new System.Workflow.ComponentModel.Compiler.TypeProvider(workflowRuntime);
typeProvider.AddAssembly(typeof(WorkflowLibrary1.Workflow1).Assembly);
workflowRuntime.AddService(typeProvider);
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
workflowRuntime.StartRuntime();
}
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
void Application_End(object sender, EventArgs e)
{
System.Workflow.Runtime.WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
workflowRuntime.StopRuntime();
}
接着,就可以在程序中运行workflow了
private void StartWorkflow()
{
WorkflowRuntime workflowRuntime = StartRuntime();
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
// Now get a refernece to the ManualWorkflowSchedulerService
ManualWorkflowSchedulerService scheduler =
workflowRuntime.GetService
<
ManualWorkflowSchedulerService
>
();
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler
<
WorkflowCompletedEventArgs
>
(WorkflowRuntime_WorkflowCompleted);
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(typeof(WorkflowLibrary1.Workflow1));
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
workflowInstance.Start();
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
// Now run the workflow. This is necessary when
//
using the ManualWorkflowSchedulerService
scheduler.RunWorkflow(workflowInstance.InstanceId);
}
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
private WorkflowRuntime StartRuntime()
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
ExternalDataExchangeService dataService = workflowRuntime.GetService
<
ExternalDataExchangeService
>
();
OrderLocalServices.OrderService orderService = workflowRuntime.GetService
<
OrderLocalServices
.OrderService
>
();
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
if (orderService == null)
{
orderService = new OrderLocalServices.OrderService();
dataService.AddService(orderService);
}
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
// Attach to the WorkflowCompleted event
workflowRuntime.WorkflowCompleted += new EventHandler
<
WorkflowCompletedEventArgs
>
(WorkflowRuntime_WorkflowCompleted);
return workflowRuntime;
}
最后,运行代码后,当运行完上图中的CodeActive后,该workflowinstance将进入等待状态(会触发workflowRuntinme的WorkflowIdled事件)。
这个时候你如果注册了SqlWorkflowPersistenceService服务,和创建了PersistenceStore数据库,则会将此
工作流保存到数据库中,已备下次使用,关于这块下次我再整理。
为什么工作流会等待了,
因为接下来的环节HandleExternalEventActive的Active必须需要触发了和他相关联的事件后,他才会继续的。
所以,我可以针对workflowRuntinme增加WorkflowIdled事件,实现事件的代码如下:
void
workflowRuntime_WorkflowIdled(
object
sender, WorkflowEventArgs e)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/ab7c8e1e2ba87b9c8e6d4a2f2e151e02.png)
{
WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"]
OrderService orderService = workflowRuntime.GetService<OrderService>();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
WorkflowInstance instance = workflowRuntime.GetLoadedWorkflows()[0];
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
instance.Load();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
//触发相关联的事件
orderService.RaiseOrderUpdatedEvent(instance.InstanceId);
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
}
这样这个工作流就整个的执行完成了。
本篇主要讲WF在asp.net运用。如下:
我的流程设置如下:
![](https://i-blog.csdnimg.cn/blog_migrate/bc119a28bc33e3f7cd3b09e26a972ce1.png)
设置了一个CodeActive和一个HandleExternalEventActive
CodeActive是执行一段代码的Active
HandleExternalEventActive是外联一个Event的Active
首先,配置web.config
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/1c4a20d0595dd90de5a8ba593f2f961b.png)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/ab7c8e1e2ba87b9c8e6d4a2f2e151e02.png)
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
简单介绍上面的配置文件
a.注册服务
这里是将一些服务注册到 Workruntime中,你也可以在代码中使用AddServcie中注册服务。
注册好服务后,就可以在代码中
ExternalDataExchangeService dataService = workflowRuntime.GetService<ExternalDataExchangeService>();
以上方式得到服务。
b.跟踪
配置跟踪信息,非常有用,我有一次调试的时候,MSDTC 服务没有启动的错误,就是查看WFTrace.log文件而获得的。
然后,在Global中启动一个WorkRunTime
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
接着,就可以在程序中运行workflow了
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![dot.gif](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
最后,运行代码后,当运行完上图中的CodeActive后,该workflowinstance将进入等待状态(会触发workflowRuntinme的WorkflowIdled事件)。
这个时候你如果注册了SqlWorkflowPersistenceService服务,和创建了PersistenceStore数据库,则会将此
工作流保存到数据库中,已备下次使用,关于这块下次我再整理。
为什么工作流会等待了,
因为接下来的环节HandleExternalEventActive的Active必须需要触发了和他相关联的事件后,他才会继续的。
所以,我可以针对workflowRuntinme增加WorkflowIdled事件,实现事件的代码如下:
![None.gif](https://i-blog.csdnimg.cn/blog_migrate/0b1f3ede97cba89e73b69c13b3b9aab7.png)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/ab7c8e1e2ba87b9c8e6d4a2f2e151e02.png)
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/1c4a20d0595dd90de5a8ba593f2f961b.png)
![dot.gif](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/e147b5e79fde86f6143c00d799f28fbd.png)
![ExpandedBlockEnd.gif](https://i-blog.csdnimg.cn/blog_migrate/2cc8acaea74fa95d72c0ed7bdc5513cd.png)
这样这个工作流就整个的执行完成了。