WorkflowApplicationUnhandledExceptionEventArgs.ExceptionSourceInstanceId 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取活动实例的唯一标识符,该标识符是未经处理的异常的源。
public:
property System::String ^ ExceptionSourceInstanceId { System::String ^ get(); };
public string ExceptionSourceInstanceId { get; }
member this.ExceptionSourceInstanceId : string
Public ReadOnly Property ExceptionSourceInstanceId As String
属性值
作为未处理的异常源的活动实例的标识符。
示例
以下示例调用引发异常的工作流。 该异常由工作流未经处理,并调用 OnUnhandledException 处理程序。 将检查 WorkflowApplicationUnhandledExceptionEventArgs 以提供有关异常的信息,并终止工作流。
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();
注解
如果活动引发异常且未经处理,则默认行为是终止工作流实例。 OnUnhandledException如果存在处理程序,它可以替代此默认行为。 此处理程序使工作流主机作者有机会提供适当的处理,例如自定义日志记录、中止工作流、取消工作流或终止工作流。