当前位置: 移动技术网 > IT编程>开发语言>.net > WPF异常捕获三种处理 UI线程, 全局异常,Task异常

WPF异常捕获三种处理 UI线程, 全局异常,Task异常

2018年08月19日  | 移动技术网IT编程  | 我要评论

奇葩网,韩德君女友,种子搜索神器2012

protected override void onstartup(startupeventargs e)
{
base.onstartup(e);
registerevents();
}

private void registerevents()
{
//taskscheduler.unobservedtaskexception += (sender, args) =>
//{
// messagebox.show(args.exception.message);
// args.setobserved();
//};

this.dispatcherunhandledexception += app_dispatcherunhandledexception;
taskscheduler.unobservedtaskexception += new eventhandler<
unobservedtaskexceptioneventargs>(taskscheduler_unobservedtaskexception);

appdomain.currentdomain.unhandledexception += currentdomain_unhandledexception;
}

private void app_dispatcherunhandledexception(object sender, dispatcherunhandledexceptioneventargs e)
{

}

static void taskscheduler_unobservedtaskexception(object sender, unobservedtaskexceptioneventargs e)
{
foreach (exception item in e.exception.innerexceptions)
{
console.writeline("异常类型:{0}{1}来自:{2}{3}异常内容:{4}",
item.gettype(), environment.newline, item.source,
environment.newline, item.message);
}
//将异常标识为已经观察到 
e.setobserved();
}

private void currentdomain_unhandledexception(object sender, unhandledexceptioneventargs e)
{
messagebox.show("unhandled exception.");
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网