WPF Application添加全局异常处理

1.取消在App.xaml中设置StartUpUrl

2.在后台的APP.Xaml.cs如下设置,先绑定异常处理的handle,再设置StartUpUrl,可以实现在前台设置一样的效果   

        public App()
        {
            App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            this.StartupUri = new Uri("MainWIndow.xaml", UriKind.Relative);
        }

        void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            throw new NotImplementedException();
        }

        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            throw new NotImplementedException();
        }

 

posted on 2014-12-19 15:57  Dunk  阅读(949)  评论(0编辑  收藏  举报

导航