-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (59 loc) · 1.95 KB
/
Copy pathProgram.cs
File metadata and controls
67 lines (59 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Threading;
using System.Windows.Forms;
namespace Boostera
{
internal static class Program
{
private static Mutex mutex = null;
private static bool hasMutex = false;
[STAThread]
static void Main()
{
NativeMethods.SetProcessDpiAwarenessContext(NativeMethods.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mutex = new Mutex(true, Application.ProductName, out hasMutex);
if (!hasMutex)
{
MessageBox.Show($@"{Application.ProductName} は既に起動中です。");
return;
}
try
{
Application.Run(new MainForm());
}
finally
{
if (hasMutex) mutex.ReleaseMutex();
}
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
try
{
Constants.Log.Logger.LogException(e.Exception);
}
catch { }
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
try
{
Constants.Log.Logger.LogException((Exception)e.ExceptionObject);
}
catch { }
}
finally
{
if (hasMutex) mutex.ReleaseMutex();
Environment.Exit(1);
}
}
}
}