using ComponentFactory.Krypton.Toolkit; using FastReport; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows.Forms; namespace NXWMS { static class Program { /// /// 应用程序的主入口点。 /// public static ApplicationContext context; /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { try { Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; new EnvironmentSettings().ReportSettings.ShowProgress = false; var processName = Process.GetCurrentProcess().ProcessName; if ((Process.GetProcessesByName(processName)).GetUpperBound(0) > 0) { KryptonMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var upgrade = new FrmLoginNew(); context = new ApplicationContext(); context.Tag = upgrade; Application.Idle += Application_Idle; //注册程序运行空闲去执行主程序窗体相应初始化代码 Application.Run(context); } } catch (Exception ex) { KryptonMessageBox.Show("系统出现未知异常,请重启系统:" + ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { var ex = e.Exception.InnerException; if (ex != null) { KryptonMessageBox.Show("系统出现未知异常," + ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var ex = e.ExceptionObject as Exception; if (ex != null) { KryptonMessageBox.Show("系统出现未知异常," + ex.InnerException.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private static void Application_Idle(object sender, EventArgs e) { Application.Idle -= Application_Idle; if (context.MainForm == null) { var login = new FrmLoginNew(); context.MainForm = login; var sp = (FrmLoginNew)context.Tag; sp.Close(); login.Show(); } } } }