WorkflowApplication.OnUnhandledException Eigenschap

Definitie

Hiermee haalt u de aanroep op of stelt u deze Func<T,TResult> in wanneer het huidige werkstroomexemplaren een niet-verwerkte uitzondering tegenkomt.

public:
 property Func<System::Activities::WorkflowApplicationUnhandledExceptionEventArgs ^, System::Activities::UnhandledExceptionAction> ^ OnUnhandledException { Func<System::Activities::WorkflowApplicationUnhandledExceptionEventArgs ^, System::Activities::UnhandledExceptionAction> ^ get(); void set(Func<System::Activities::WorkflowApplicationUnhandledExceptionEventArgs ^, System::Activities::UnhandledExceptionAction> ^ value); };
public Func<System.Activities.WorkflowApplicationUnhandledExceptionEventArgs,System.Activities.UnhandledExceptionAction> OnUnhandledException { get; set; }
member this.OnUnhandledException : Func<System.Activities.WorkflowApplicationUnhandledExceptionEventArgs, System.Activities.UnhandledExceptionAction> with get, set
Public Property OnUnhandledException As Func(Of WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction)

Waarde van eigenschap

De gemachtigde die wordt aangeroepen wanneer een werkstroomexemplaren een onverwerkte uitzondering tegenkomt.

Voorbeelden

In het volgende voorbeeld wordt een werkstroom aangeroepen die een uitzondering genereert. De uitzondering wordt niet verwerkt door de werkstroom en de OnUnhandledException handler wordt aangeroepen. De WorkflowApplicationUnhandledExceptionEventArgs worden geïnspecteerd om informatie te verstrekken over de uitzondering en de werkstroom wordt beëindigd.

Activity wf = new Sequence
{
    Activities =
     {
         new WriteLine
         {
             Text = "Starting the workflow."
         },
         new Throw
        {
            Exception = new InArgument<Exception>((env) =>
                new ApplicationException("Something unexpected happened."))
        },
        new WriteLine
         {
             Text = "Ending the workflow."
         }
     }
};

WorkflowApplication wfApp = new WorkflowApplication(wf);

wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
    // Display the unhandled exception.
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
        e.InstanceId, e.UnhandledException.Message);

    Console.WriteLine("ExceptionSource: {0} - {1}",
        e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);

    // Instruct the runtime to terminate the workflow.
    return UnhandledExceptionAction.Terminate;

    // Other choices are UnhandledExceptionAction.Abort and
    // UnhandledExceptionAction.Cancel
};

wfApp.Run();

Opmerkingen

Zowel OnUnhandledException als WorkflowUnhandledExceptionBehavior dicteer het gedrag van de runtime wanneer een uitzondering niet wordt verwerkt in de werkstroom; heeft echter WorkflowUnhandledExceptionBehavior de mogelijkheid om een onderbroken werkstroom in het persistentiearchief te laten, terwijl OnUnhandledException dat niet het geval is. De reden hiervoor is dat wat er gebeurt met een onderbroken werkstroom hostspecifiek is en WorkflowApplication niet. Als u deze functionaliteit wilt implementeren met behulp van WorkflowApplication, maakt u een aangepaste PersistenceParticipant functionaliteit met dit gedrag.

Van toepassing op