【发布时间】:2012-02-18 20:43:33
【问题描述】:
我正在尝试使用 AppDomain.CurrentDomain.UnhandledException 记录我的异常。
AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
public static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
HandleException(e.ExceptionObject as Exception);
}
当我在服务器中遇到异常时,我会在调试时在客户端中遇到错误,但永远不会触发与 AppDomain.CurrentDomain.UnhandledException 挂钩的事件。
服务器:
[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
public class Service : IService
{
public string GetError()
{
throw new ApplicationException();
}
}
客户:
public void GetError()
{
this.service.BeginGetError(OnGetErrorCompleted, null);
}
public void OnGetErrorCompleted(IAsyncResult result)
{
var value = this.service.EndGetError(result);
}
这不起作用,除非我使用 Distpacher.BeginInvoke..
public void OnGetErrorCompleted(IAsyncResult result)
{
this.Dispatcher.BeginInvoke((Action)(() =>
{
var value = this.service.EndGetError(result);
}));
}
有人知道为什么吗? 我认为 AppDomain.CurrentDomain.UnhandledException 会在任何线程出现异常的情况下被触发! :S
【问题讨论】:
标签: c# .net web-services exception