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 が格納されます。

イベントの処理の詳細については、「イベントの 処理と発生」を参照してください。

適用対象