111,126
社区成员
发帖
与我相关
我的任务
分享
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
AppDomain.CurrentDomain.AppendPrivatePath("System");
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
Application.ThreadException += new ThreadExceptionEventHandler(Program.Application_ThreadException);
bool firstInstance;
mutex = new Mutex(true, @"Global\"+myTool.GetMD5Hash(Application.StartupPath), out firstInstance);
try
{
if (firstInstance)
{
Application.Run(new F_Main());
}
}
finally
{
//只有第一个实例获得控制权,因此只有在这种情况下才需要ReleaseMutex,否则会引发异常。
if (firstInstance)
{
mutex.ReleaseMutex();
}
mutex.Close();
mutex = null;
}
}