| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using System;
- using System.IO;
- using System.Reflection;
- using System.Windows;
- namespace SAGA.RevitUtils.ErrorSupports
- {
- public class ErrorHandlers
- {
- private static AppDomain _appDoamin;
- private static void appDoamin_DomainUnload(object sender, EventArgs e)
- {
- _appDoamin = null;
- }
- private static void appDoamin_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- if (!TErrorSupport.IsShowed)
- {
- MessageShow.Show(e.ExceptionObject as Exception, false, "");
- }
- }
- public static void Start()
- {
- if (_appDoamin == null)
- {
- _appDoamin = AppDomain.CurrentDomain;
- _appDoamin.UnhandledException += new UnhandledExceptionEventHandler(ErrorHandlers.appDoamin_UnhandledException);
- _appDoamin.DomainUnload += new EventHandler(ErrorHandlers.appDoamin_DomainUnload);
-
- }
- //界面异常捕获 xls 2018-8-7
- // Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
- //var tempPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ErrorHandlers)).Location);
- //var path = Environment.GetEnvironmentVariable("PATH") + tempPath;
- //Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
- //string assemblyName = "System.Net.Http.Formatting, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
- //Assembly.Load(assemblyName);
- }
- private static void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
- {
- if (!TErrorSupport.IsShowed)
- {
- MessageShow.Show(e.Exception as Exception, false, "");
- }
- e.Handled = true;
- }
- public static void Stop()
- {
- if (_appDoamin != null)
- {
- _appDoamin.UnhandledException -= new UnhandledExceptionEventHandler(ErrorHandlers.appDoamin_UnhandledException);
- _appDoamin.DomainUnload -= new EventHandler(ErrorHandlers.appDoamin_DomainUnload);
- _appDoamin = null;
- }
- //Application.Current.DispatcherUnhandledException -= Current_DispatcherUnhandledException;
- }
- }
- }
|