using ProjectManagementSystem.Common.Extenions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProjectManagementSystem
{
static class Program
{
///
/// 应用程序的主入口点。
///
[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)
{
string cultureInfo = Common.Function.AppSetting.TryGetValue("CultureInfo");
if(!string.IsNullOrEmpty(cultureInfo))
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureInfo);
}
Application.Run(new MainForm());
}
else
{
MessageBox.Show("应用程序只能启动一个实例!!!");
Application.Exit();
}
}
}
catch (System.Exception exception)
{
Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(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;
Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(exception);
if (exception.InnerException != null)
{
Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(exception.InnerException);
}
MessageBox.Show("应用程序有未处理的异常!!!" + exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception);
if (e.Exception.InnerException != null)
{
Common.Logger.CLog.Instance.SystemLog.WriteExceptionCaller(e.Exception.InnerException);
}
MessageBox.Show("应用程序线程异常!!!" + e.Exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}