WorkflowApplicationUnhandledExceptionEventArgs.ExceptionSourceInstanceId Egenskap

Definition

Hämtar den unika identifieraren för aktivitetsinstansen som är källan till det ohanterade undantaget.

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

Egenskapsvärde

En identifierare för den aktivitetsinstans som är källan till det ohanterade undantaget.

Exempel

I följande exempel anropas ett arbetsflöde som utlöser ett undantag. Undantaget hanteras inte av arbetsflödet och OnUnhandledException-hanteraren anropas. WorkflowApplicationUnhandledExceptionEventArgs inspekteras för att ange information om undantaget och arbetsflödet avslutas.

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

Kommentarer

Om ett undantag utlöses av en aktivitet och inte hanteras är standardbeteendet att avsluta arbetsflödesinstansen. Om det finns en OnUnhandledException hanterare kan den åsidosätta det här standardbeteendet. Den här hanteraren ger upphovsmannen till arbetsflödet en möjlighet att tillhandahålla lämplig hantering, till exempel anpassad loggning, avbryta arbetsflödet, avbryta arbetsflödet eller avsluta arbetsflödet.

Gäller för