Condividi tramite


WorkflowApplicationUnhandledExceptionEventArgs.ExceptionSourceInstanceId Proprietà

Definizione

Ottiene l'identificatore unico dell'istanza dell'attività che rappresenta l'origine dell'eccezione non gestita.

public:
 property System::String ^ ExceptionSourceInstanceId { System::String ^ get(); };
public string ExceptionSourceInstanceId { get; }
member this.ExceptionSourceInstanceId : string
Public ReadOnly Property ExceptionSourceInstanceId As String

Valore della proprietà

Identificatore dell'istanza dell'attività che rappresenta l'origine dell'eccezione non gestita.

Esempio

Nell'esempio seguente viene richiamato un flusso di lavoro che genera un'eccezione. L'eccezione non viene gestita dal flusso di lavoro e viene richiamato il gestore OnUnhandledException. Gli argomenti WorkflowApplicationUnhandledExceptionEventArgs vengono controllati per fornire informazioni sull'eccezione e il flusso di lavoro viene terminato.

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

Commenti

Se un'eccezione viene generata da un'attività ma non viene gestita, il comportamento predefinito prevede l'interruzione dell'istanza del flusso di lavoro. Se presente, un gestore OnUnhandledException può eseguire l'override di questo comportamento predefinito. Questo gestore consente all'autore dell'host del flusso di lavoro di fornire la gestione appropriata, ad esempio la registrazione personalizzata, l'interruzione, l'annullamento o la chiusura del flusso di lavoro.

Si applica a