using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using WinFormControl; namespace ButcherFactory.Login { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { try { //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += Application_ThreadException; //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; var aProcessName = Process.GetCurrentProcess().ProcessName; if ((Process.GetProcessesByName(aProcessName)).GetUpperBound(0) > 0) { SoundPalyUtil.PlaySound(SoundType.Error); UMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告"); } else { // Mapper.Initialize(cfg => { // cfg.AddProfile(); // cfg.CreateMap(); // }); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login()); } } catch (Exception e) { // LogUtil.WriteError(e); SoundPalyUtil.PlaySound(SoundType.Error); MessageBox.Show("错误:" + e.Message + " \n详细信息:" + e.StackTrace); //UMessageBox.Show("错误:" + e.Message ); } } /// /// 在发生未处理异常时处理的方法 /// /// /// private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { var ex = e.Exception; var err = String.Empty; if (ex != null) { //LogUtil.WriteError(ex); err = ex.Message; } SoundPalyUtil.PlaySound(SoundType.Error); MessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace); // UMessageBox.Show("错误:" + err); } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var err = String.Empty; var ex = e.ExceptionObject as Exception; if (ex != null) { //LogUtil.WriteError(ex); err = ex.Message; } SoundPalyUtil.PlaySound(SoundType.Error); MessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace); //UMessageBox.Show("错误:" + err); } } }