1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ProjectManagementSystem
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- //Application.Run(new MainForm());
- Program.InitApplication();
- }
- public static void InitApplication()
- {
- System.Windows.Forms.Application.ThreadException += Application_ThreadException;
- System.AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- try
- {
- bool flag;
- using (new System.Threading.Mutex(true, "Global\\" + System.Windows.Forms.Application.ProductName, out flag))
- {
- if (flag)
- {
- Application.Run(new MainForm());
- }
- else
- {
- MessageBox.Show("应用程序只能启动一个实例!!!");
- Application.Exit();
- }
- }
- }
- catch (System.Exception exception)
- {
- MessageBox.Show("应用程序运行异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- Application.Exit();
- }
- }
- private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- Exception exception = e.ExceptionObject as Exception;
- MessageBox.Show("应用程序有未处理的异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- MessageBox.Show("应用程序线程异常!!!" + e.Exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
|