介绍
System.Workflow.Runtime.WorkflowRuntime
文件: system.workflow.runtime.dll
在工作流的运行环境(宿主)中,为工作流提供运行的引擎
1.WorkflowRuntime在宿主中以自已独立的线程运行例
2.WorkflowRuntime可以加载多个工作流实例,每个工作流实例在WorkflowRuntime有独立的线程
3.同一宿主可可以实例化多个引擎,他们可以同时工作基本使用
配置并启动引擎 |
Dim 引擎 As New WorkflowRuntime() '定义引擎实例 引擎.AddService(加载服务)'向引擎加载服务 AddHandler 引擎.事件, AddressOf 事件回调程序 '为引擎绑定事件 引擎.StartRuntime() '启动引擎 |
在引擎中创建 并运行实例 |
Dim 工作流模板类As Type '定义一个Type型对象 工作流模板类= GetType(Workflow1) '得要要运行的工作流的类型名 Dim 实例 As WorkflowInstance '定义一个要由引擎运行的工作流实例 '用引擎.CreateWorkflow方法返回实例,此时该实例已在引擎内创建,但还没启动 实例= 引擎.CreateWorkflow(工作流模板类) 实例.Start() '运行引擎中的实例 |
停止引擎 |
'停止引擎 引擎.StopRuntime() |
方法
如何加载服务见WWF_持久化
加载 服务 得到 服务 |
AddService |
添加一个服务到工作流引擎 引擎.AddService (object) |
RemoveService |
从工作流引擎移除一个服务 引擎.RemoveService(object) |
|
GetService |
从加载到引擎中的指定服务 Function GetService (serviceType As Type) As Object Function GetService(Of T)() As T |
|
GetAllServices |
得到所有加载到引擎中的服务 Function GetAllServices(Of T) As ReadOnlyCollection(Of T) Function GetAllServices (serviceType As Type) As ReadOnlyCollection(Of Object) |
|
建立 实例 得到 实例 |
CreateWorkflow |
在引擎中建立一个实例,并将该实例返回 使用工作流类开为参数 Function CreateWorkflow ( workflowType As Type ) As WorkflowInstance Function CreateWorkflow (workflowType As Type,参数 As Dictionary(Of String, Object)) As WorkflowInstance 使用一个XmlReader为参数 Function CreateWorkflow(ByVal workflowDefinitionReader As XmlReader) As WorkflowInstance Function CreateWorkflow(ByVal workflowDefinitionReader As XmlReader, ByVal rulesReader As XmlReader, ByVal 参数As Dictionary(Of String, Object)) As WorkflowInstance |
GetLoadedWorkflows |
得到内存中所有工作流的集合 Function GetLoadedWorkflows As ReadOnlyCollection(Of WorkflowInstance) |
|
GetWorkflow |
使用 Function GetWorkflow(ByVal instanceId As Guid) As WorkflowInstance |
|
引擎 控制 |
StartRuntime |
启用引擎 引擎.StartRuntime() |
StopRuntime |
停止引擎,停止引擎后,引擎并没有释放,引擎中的实例也存中,只是所有的执行都被系统级挂起,当重新启动引擎时,所有的实例还可粥运行 引擎.StopRuntime() |
|
资源释放 |
Dispose |
释放工作流引擎资源 引擎.Dispose() |
事件
有些事件将在具体实用中详细说明
ByVal sender As Object返回引发该事件的工作流引擎,当一个宿主实例化了多个引擎,而这些引擎又绑定到同一组事件上时,可以使用sender参数得到触发该事件的引擎
ServicesException _NotHandled |
Occurs when a service that is derived from the WorkflowRuntimeService class calls RaiseServicesExceptionNotHandledEvent(与加载服务有关) |
Sub OnServicesExceptionNotHandled(ByVal sender As Object, ByVal e As ServicesExceptionNotHandledEventArgs) 'ServicesExceptionNotHandledEventArgs ' e.Exception异常信息 ' e.WorkflowInstanceId 工作流实例的GUID |
|
Started |
引擎启动后 |
Sub OnStarted(ByVal sender As Object, ByVal e As WorkflowRuntimeEventArgs) 'WorkflowRuntimeEventArgs 'e.IsStarted 是否启动 |
|
Stopped |
引擎停止后 |
Sub OnStopped(ByVal sender As Object, ByVal e As WorkflowRuntimeEventArgs) 'WorkflowRuntimeEventArgs 'e.IsStarted 是否启动 |
|
WorkflowAborted |
引擎中的某个实例:被中断执行后 |
Sub OnWorkflowAborted(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowCompleted |
引擎中的某个实例:完成后. |
Sub OnWorkflowCompleted(ByVal sender As Object, ByVal e As WorkflowCompletedEventArgs) 'WorkflowCompletedEventArgs ' e.OutputParameters用参数方式与实例的属性进行通信 ' e.WorkflowInstance 工作流实例 ' e.WorkflowInstance 引发该事件的实例 |
|
WorkflowCreated |
引擎中的某个实例: 被创建后 |
Sub OnWorkflowCreated(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowIdled |
引擎中的某个实例: 进入空闭状态, 如Delay控件,CallExternalMethod控件, 会触发该事件 |
Sub OnWorkflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowLoaded |
引擎中的某个实例: 加载到内存时 |
Sub OnWorkflowLoaded(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowPersisted |
引擎中的某个实例: 进入持久化状态后, 注,如果没有加载持久化服务,而调用持久化方法,该事件仍会触发,但实例并没有被持久化 |
Sub OnWorkflowPersisted(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowResumed |
引擎中的某个实例:从挂起状态恢复后 |
Sub OnWorkflowResumed(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowStarted |
引擎中的某个实例:被启动后 |
Sub OnWorkflowStarted(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |
|
WorkflowSuspended |
引擎中的某个实例:被暂停后,如Suspend控件会触发该事件 |
Sub OnWorkflowSuspended(ByVal sender As Object, ByVal e As WorkflowSuspendedEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 'e.Error 暂停信息 |
|
WorkflowTerminated |
引擎中的某个实例:终止后,如工作流内部的异常会引起终止 |
Sub OnWorkflowTerminated(ByVal sender As Object, ByVal e As WorkflowTerminatedEventArgs) 'WorkflowTerminatedEventArgs ' e.Exception 异常 ' e.WorkflowInstance 工作流实例 |
|
WorkflowUnloaded |
引擎中的某个实例:从内存中移出后 |
Sub OnWorkflowUnloaded(ByVal sender As Object, ByVal e As WorkflowEventArgs) 'WorkflowEventArgs 'e.WorkflowInstance 工作流实例 |