-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (53 loc) · 1.62 KB
/
Program.cs
File metadata and controls
60 lines (53 loc) · 1.62 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
namespace SimpleSync;
public static class Program
{
private const string SingleInstanceMutexName = "SimpleSync_1E3A44B2_6F6A_4B70_A8D6_4B5D8E0E0D50";
[STAThread]
static void Main()
{
using var mutex = new Mutex(initiallyOwned: true, GetSingleInstanceMutexName(IsDebugBuild()), out var createdNew);
if (!createdNew)
{
MessageBox.Show("simple sync가 이미 실행 중입니다.", "simple sync", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
ApplicationConfiguration.Initialize();
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += (_, e) => ShowUnhandledError(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
{
if (e.ExceptionObject is Exception exception)
{
ShowUnhandledError(exception);
}
};
try
{
Application.Run(new MainForm());
}
catch (Exception ex)
{
ShowUnhandledError(ex);
}
}
public static string GetSingleInstanceMutexName(bool isDebugBuild)
{
return isDebugBuild ? SingleInstanceMutexName + "_Debug" : SingleInstanceMutexName;
}
private static bool IsDebugBuild()
{
#if DEBUG
return true;
#else
return false;
#endif
}
private static void ShowUnhandledError(Exception exception)
{
MessageBox.Show(
exception.Message,
"simple sync error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}