using GalaSoft.MvvmLight.Threading; using System; using System.IO; using System.Linq; using System.Windows; namespace MuchInfo.Chart.App { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { static App() { CopySqliteFile(); DispatcherHelper.Initialize(); } public App() { this.DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; } /// /// 处理Dispatcher线程异常 /// /// The source of the event. /// The instance containing the event data. private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { MessageBox.Show(e.Exception.Message); } /// /// 处理Domain异常 /// /// The source of the event. /// The instance containing the event data. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { MessageBox.Show((e.ExceptionObject as Exception).Message); } private static void CopySqliteFile() { var is64 = Environment.Is64BitOperatingSystem; var sqliteFilePath = Environment.CurrentDirectory; sqliteFilePath = Path.Combine(sqliteFilePath, is64 ? "x64" : "x86"); var dirInfo = new DirectoryInfo(sqliteFilePath); if (dirInfo.Exists) { var fileInfos = dirInfo.GetFiles("*.dll", SearchOption.TopDirectoryOnly); if (!fileInfos.Any()) return; foreach (var fileInfo in fileInfos) { fileInfo.CopyTo(Path.Combine(Environment.CurrentDirectory, fileInfo.Name), true); } } } } }