WorkflowRuntime.ServicesExceptionNotHandled 事件

定義

在衍生自 WorkflowRuntimeService 類別的服務呼叫 RaiseServicesExceptionNotHandledEvent(Exception, Guid) 時發生。

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

如需處理事件的詳細資訊,請參閱 處理和引發事件

適用於