WorkflowRuntime.ServicesExceptionNotHandled 事件

定义

public:
 event EventHandler<System::Workflow::Runtime::ServicesExceptionNotHandledEventArgs ^> ^ ServicesExceptionNotHandled;
public event EventHandler<System.Workflow.Runtime.ServicesExceptionNotHandledEventArgs> ServicesExceptionNotHandled;
member this.ServicesExceptionNotHandled : EventHandler<System.Workflow.Runtime.ServicesExceptionNotHandledEventArgs> 
Public Custom Event ServicesExceptionNotHandled As EventHandler(Of ServicesExceptionNotHandledEventArgs) 
Public Event ServicesExceptionNotHandled As EventHandler(Of ServicesExceptionNotHandledEventArgs) 

事件类型

示例

下面的代码示例演示如何使用工作流宿主中的 WorkflowRuntime 功能。 该代码将 ServicesExceptionNotHandled 与一个事件处理程序(即一个名为 OnExceptionNotHandled 的方法)相关联。

此代码示例是 自定义持久性服务示例的一部分。

static void Main()
{
    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
        try
        {
            // engine will unload workflow instance when it is idle
            workflowRuntime.AddService(new FilePersistenceService(true));

            workflowRuntime.WorkflowCreated += OnWorkflowCreated;
            workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
            workflowRuntime.WorkflowIdled += OnWorkflowIdle;
            workflowRuntime.WorkflowUnloaded += OnWorkflowUnload;
            workflowRuntime.WorkflowLoaded += OnWorkflowLoad;
            workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
            workflowRuntime.ServicesExceptionNotHandled += OnExceptionNotHandled;

            workflowRuntime.CreateWorkflow(typeof(PersistenceServiceWorkflow)).Start();

            waitHandle.WaitOne();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception \n\t Source: {0} \n\t Message: {1}", e.Source, e.Message);
        }
        finally
        {
            workflowRuntime.StopRuntime();
            Console.WriteLine("Workflow runtime stopped, program exiting... \n");
        }
    }
}
Shared Sub Main()

    Using currentWorkflowRuntime As New WorkflowRuntime()
        Try

            ' engine will unload workflow instance when it is idle
            currentWorkflowRuntime.AddService(New FilePersistenceService(True))

            AddHandler currentWorkflowRuntime.WorkflowCreated, AddressOf OnWorkflowCreated
            AddHandler currentWorkflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
            AddHandler currentWorkflowRuntime.WorkflowIdled, AddressOf OnWorkflowIdled
            AddHandler currentWorkflowRuntime.WorkflowUnloaded, AddressOf OnWorkflowUnloaded
            AddHandler currentWorkflowRuntime.WorkflowLoaded, AddressOf OnWorkflowLoaded
            AddHandler currentWorkflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated
            AddHandler currentWorkflowRuntime.ServicesExceptionNotHandled, AddressOf OnExceptionNotHandled

            currentWorkflowRuntime.CreateWorkflow(GetType(PersistenceServiceWorkflow)).Start()

            waitHandle.WaitOne()

        Catch e As Exception
            Console.WriteLine("Exception \n\t Source: 0} \n\t Message: 1}", e.Source, e.Message)
        Finally
            currentWorkflowRuntime.StopRuntime()
            Console.WriteLine("Workflow runtime stopped, program exiting... \n")
        End Try
    End Using
End Sub

注解

派生自 WorkflowRuntimeService 类的服务可调用 RaiseServicesExceptionNotHandledEvent 方法,以通知 ServicesExceptionNotHandled 事件的订户在执行过程中出现无法处理的异常。 您可以订阅此事件以实现恢复机制。

在工作流运行时引擎尚未创建工作流实例前引发此事件,同时将出现一个异常。 在此方案中,通知宿主应用程序发生异常的唯一方法是引发此事件。 但是,工作流运行时引擎不直接调用此方法。 工作流运行时引擎而是向工作流实例发送异常,或者在没有实例的情况下将异常引发回调用方(本例中调用方实际上是激发此事件的服务)。 如果要创建自己的持久性服务或计划程序,您必须自己使用 RaiseServicesExceptionNotHandledEvent 基方法来实现此事件。

对于 ServicesExceptionNotHandled 事件,发送方包含 WorkflowRuntime,而 WorkflowEventArgs 包含使用服务的工作流实例的 Guid,以及无法处理的 Exception

有关处理事件的详细信息,请参阅 处理和引发事件

适用于