1、为引擎绑定事件引擎.StartRuntime() 启动引擎在引擎中创建并运行实例Dim 工作流模板类As Type 定义一个Type型对象工作流模板类= GetType(Workflow1) 得要要运行的工作流的类型名Dim 实例 As WorkflowInstance 定义一个要由引擎运行的工作流实例用引擎.CreateWorkflow方法返回实例,此时该实例已在引擎内创建,但还没启动实例= 引擎.CreateWorkflow(工作流模板类)实例.Start() 运行引擎中的实例停止引擎引擎.StopRuntime()方法加载服务得到AddService添加一个服务到工作流引擎 引擎.Add
2、Service (object)RemoveService从工作流引擎移除一个服务 引擎.RemoveService(object) GetService从加载到引擎中的指定服务Function GetService (serviceType As Type) As ObjectFunction GetService(Of T)() As TGetAllServices得到所有加载到引擎中的服务Function GetAllServices(Of T) As ReadOnlyCollection(Of T)Function GetAllServices (serviceType As Type
3、) As ReadOnlyCollection(Of Object)建立实例CreateWorkflow在引擎中建立一个实例,并将该实例返回使用工作流类开为参数Function CreateWorkflow ( workflowType As Type ) As WorkflowInstanceFunction CreateWorkflow (workflowType As Type,参数 As Dictionary(Of String, Object) As WorkflowInstance使用一个XmlReader为参数Function CreateWorkflow(ByVal workf
4、lowDefinitionReader As XmlReader) As WorkflowInstanceFunction CreateWorkflow(ByVal workflowDefinitionReader As XmlReader, ByVal rulesReader As XmlReader, ByVal 参数As Dictionary(Of String, Object) As WorkflowInstanceGetLoadedWorkflows得到内存中所有工作流的集合 Function GetLoadedWorkflows As ReadOnlyCollection(Of W
5、orkflowInstance)GetWorkflow使用 Guid参数,从引擎中得到指定ID的工作流实例 Function GetWorkflow(ByVal instanceId As Guid) As WorkflowInstance如果引擎中没有指定GUID的实例,会报The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance如果加载了SqlWorkflowPersistenceService,没有所引的
6、实例会报Workflow with id GUID not found in state persistence store.引擎控制StartRuntime启用引擎引擎.StartRuntime() StopRuntime停止引擎,停止引擎后,引擎停止后,引擎并没有释放,引擎中的实例也存在,只是所有的执行都被系统级挂起,当重新启动引擎时,所有的实例还可继续运行资源释放Dispose释放工作流引擎资源引擎.Dispose()事件ByVal sender As Object返回引发该事件的工作流引擎,当一个宿主实例化了多个引擎,而这些引擎又绑定到同一组事件上时,可以使用sender参数得到触发该
7、事件的引擎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) ServicesExceptionNotHandledEve
8、ntArgs e.Exception异常信息 e.WorkflowInstanceId 工作流实例的GUIDStarted引擎启动后 Sub OnStarted(ByVal sender As Object, ByVal e As WorkflowRuntimeEventArgs)WorkflowRuntimeEventArgse.IsStarted 是否启动Stopped引擎停止后 Sub OnStopped(ByVal sender As Object, ByVal e As WorkflowRuntimeEventArgs)WorkflowAborted引擎中的某个实例:被中断执行后 S
9、ub OnWorkflowAborted(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowEventArgse.WorkflowInstance 工作流实例WorkflowCompleted完成后. Sub OnWorkflowCompleted(ByVal sender As Object, ByVal e As WorkflowCompletedEventArgs)WorkflowCompletedEventArgs e.OutputParameters用参数方式与实例的属性进行通信 e.WorkflowInstan
10、ce 工作流实例 e.WorkflowInstance 引发该事件的实例WorkflowCreated 被创建后 Sub OnWorkflowCreated(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowIdled 进入空闭状态, 如Delay控件,CallExternalMethod控件,会触发该事件 Sub OnWorkflowIdled(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowLoaded 加载到内存时 Sub OnWorkflow
11、Loaded(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowPersisted 进入持久化状态后,注,如果没有加载持久化服务,而调用持久化方法,该事件仍会触发,但实例并没有被持久化 Sub OnWorkflowPersisted(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowResumed从挂起状态恢复后 Sub OnWorkflowResumed(ByVal sender As Object, ByVal e As WorkflowEvent
12、Args)WorkflowStarted被启动后 Sub OnWorkflowStarted(ByVal sender As Object, ByVal e As WorkflowEventArgs)WorkflowSuspended被暂停后,如Suspend控件会触发该事件 Sub OnWorkflowSuspended(ByVal sender As Object, ByVal e As WorkflowSuspendedEventArgs)e.Error 暂停信息WorkflowTerminated终止后,如工作流内部的异常会引起终止 Sub OnWorkflowTerminated(B
13、yVal sender As Object, ByVal e As WorkflowTerminatedEventArgs)WorkflowTerminatedEventArgs e.Exception 异常WorkflowUnloaded从内存中移出后 Sub OnWorkflowUnloaded(ByVal sender As Object, ByVal e As WorkflowEventArgs)事件代码快速粘贴 AddHandler 引擎.ServicesExceptionNotHandled, AddressOf OnServicesExceptionNotHandled AddH
14、andler 引擎.Started, AddressOf OnStarted AddHandler 引擎.Stopped, AddressOf OnStopped AddHandler 引擎.WorkflowAborted, AddressOf OnWorkflowAborted AddHandler 引擎.WorkflowCompleted, AddressOf OnWorkflowCompleted AddHandler 引擎.WorkflowCreated, AddressOf OnWorkflowCreated AddHandler 引擎.WorkflowIdled, AddressO
15、f OnWorkflowIdled AddHandler 引擎.WorkflowLoaded, AddressOf OnWorkflowLoaded AddHandler 引擎.WorkflowPersisted, AddressOf OnWorkflowPersisted AddHandler 引擎.WorkflowResumed, AddressOf OnWorkflowResumed AddHandler 引擎.WorkflowStarted, AddressOf OnWorkflowStarted AddHandler 引擎.WorkflowSuspended, AddressOf O
16、nWorkflowSuspended AddHandler 引擎.WorkflowTerminated, AddressOf OnWorkflowTerminated AddHandler 引擎.WorkflowUnloaded, AddressOf OnWorkflowUnloaded#Region 引擎事件加载服务 Sub OnServicesExceptionNotHandled(ByVal sender As Object, ByVal e As System.Workflow.Runtime.ServicesExceptionNotHandledEventArgs) Console.
17、WriteLine() Console.WriteLine(-OnServicesExceptionNotHandled-)有实例完成: + e.WorkflowInstanceId.ToString)异常信息 + e.Exception.Message)- End Sub-OnStarted-引擎启动状态: + e.IsStarted.ToString)-OnStopped-被中断后-OnWorkflowAborted-被中断的实例: + e.WorkflowInstance.InstanceId.ToString)当有实例完成时-OnWorkflowCompleted- + e.WorkflowInstance.InstanceId.ToString()sender: + sender.ToString)当有实例被创建后-OnWorkflowCreated-有实例被创建: TextBox1.Text = e.WorkflowInstance.InstanceId.ToString当有实例进入空闭状态-OnWorkflowIdled-有实例进入空闭状态:当有实例加载到内存时-OnWorkflowLoaded-有实例加载到内存时:当有实例进入持久化状态后-OnWorkflowPersisted-有实例进入持久化状态: + e.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1