WorkflowApplication.OnUnhandledException Eigenschaft

Definition

Ruft ab oder legt fest, die Func<T,TResult> aufgerufen wird, wenn die aktuelle Workflowinstanz auf eine unbehandelte Ausnahme stößt.

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)

Eigenschaftswert

Der Delegat, der aufgerufen wird, wenn eine Workflowinstanz auf eine unbehandelte Ausnahme stößt.

Beispiele

Im folgenden Beispiel wird ein Workflow aufgerufen, der eine Ausnahme auslöst. Die Ausnahme wird vom Workflow nicht behandelt, und der OnUnhandledException-Handler wird aufgerufen. Die WorkflowApplicationUnhandledExceptionEventArgs werden überprüft, um Informationen zur Ausnahme bereitzustellen, und der Workflow wird beendet.

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();

Hinweise

Sowohl das OnUnhandledException Verhalten der Laufzeit, wenn eine Ausnahme im Workflow nicht behandelt wird, aber WorkflowUnhandledExceptionBehavior die Möglichkeit hat, WorkflowUnhandledExceptionBehavior einen angehaltenen Workflow im Persistenzspeicher zu verlassen, während OnUnhandledException dies nicht der Fall ist. Der Grund dafür ist, dass das, was mit einem angehaltenen Workflow passiert, hostspezifisch ist und WorkflowApplication nicht. Wenn Sie diese Funktionalität mithilfe von WorkflowApplication"Implementieren" implementieren möchten, erstellen Sie einen Benutzerdefinierten, PersistenceParticipant der dieses Verhalten aufweist.

Gilt für: