WorkflowRuntime.ServicesExceptionNotHandled Événement

Définition

Se produit lorsqu'un service dérivé de la classe WorkflowRuntimeService appelle 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) 

Type d'événement

Exemples

L'exemple de code suivant montre comment utiliser les fonctionnalités WorkflowRuntime d'un hôte de workflow. Le code associe l'événement ServicesExceptionNotHandled à un gestionnaire d'événements, une méthode nommée OnExceptionNotHandled.

Cet exemple de code fait partie de l’exemple de service de persistance personnalisée.

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

Remarques

Un service dérivé de la classe WorkflowRuntimeService peut appeler la méthode RaiseServicesExceptionNotHandledEvent pour informer des abonnés à l'événement ServicesExceptionNotHandled qu'une exception qu'il ne pouvait pas gérer s'est produite pendant son exécution. Vous pouvez vous abonner à cet événement pour implémenter un mécanisme de récupération.

Cet événement est déclenché lorsqu'une instance de workflow n'a pas encore été créée par le moteur d'exécution de workflow et qu'une exception se produit. Dans ce scénario, la seule méthode pour informer une application hôte qu'une exception a eu lieu est de déclencher cet événement. Toutefois, le moteur d'exécution de workflow ne l'appelle pas directement. À la place, le moteur d'exécution de workflow remet une exception à l'instance de workflow ou, s'il n'y a aucune instance, renvoie à l'appelant, qui dans ce cas est réellement le service qui déclenche cet événement. Si vous créez votre propre service de persistance ou de planificateur, vous devez implémenter cet événement vous-même à l'aide de la méthode de base RaiseServicesExceptionNotHandledEvent.

Pour l'événement ServicesExceptionNotHandled, l'expéditeur contient l'objet WorkflowRuntime, et l'objet WorkflowEventArgs contient l'objet Guid de l'instance de workflow qui utilisait le service et l'objet Exception qui n'a pas pu être géré.

Pour plus d’informations sur la gestion des événements, consultez Gestion et déclenchement d’événements.

S’applique à