-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
165 lines (142 loc) · 5.44 KB
/
Copy pathProgram.cs
File metadata and controls
165 lines (142 loc) · 5.44 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using Lib.Common;
using OpenVisionLab._1._Core;
using OpenVisionLab.Logging;
using RJCodeUI_M1;
using RJCodeUI_M1.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OpenVisionLab
{
static class Program
{
/// <summary>
/// 해당 애플리케이션의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Mutex mutex = new Mutex(true, "OpenVisionLab", out bool bNew);
if (bNew)
{
if (null == System.Windows.Application.Current)
{
new System.Windows.Application().ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
}
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//UIAppearance.FormBorderSize = 5;
SettingsManager.LoadApperanceSettings();//Load current appearance settings.
ApplicationRuntimeContext runtimeContext = ApplicationRuntimeContext.CreateDefault();
runtimeContext.Global.System.ApplyLogConfig();
OVLog.Write(LogCategory.System, LogLevel.Info, $"Application ready. Version {AppVersion.VERSION}");
StartupSplashScreen splashScreen = StartupSplashScreen.Start(
$"VERSION : {AppVersion.VERSION} - {AppVersion.DATETIME_UPDATED} ({AppVersion.MANAGER})",
null);
#if Release
#endif
Application.Run(new FormMainFrame(splashScreen.Form, runtimeContext));
OVLog.Write(LogCategory.System, LogLevel.Info, "Application shutdown.");
splashScreen.Dispose();
mutex.ReleaseMutex();
}
else
{
AppCommon.ShowdialogMessageBox("Program Already Running", "Check Job Process");
Application.Exit();
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
OVLog.Write(LogCategory.System, LogLevel.Error, e.ExceptionObject?.ToString() ?? "Unhandled domain exception.");
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
OVLog.Write(LogCategory.System, LogLevel.Error, e.Exception?.ToString() ?? "Unhandled UI thread exception.");
}
private sealed class StartupSplashScreen : IDisposable
{
private readonly ManualResetEventSlim formReady = new ManualResetEventSlim(false);
private readonly Thread thread;
private readonly string versionText;
private readonly Action<string> versionLogAction;
private FormInit form;
private StartupSplashScreen(string versionText, Action<string> versionLogAction)
{
this.versionText = versionText;
this.versionLogAction = versionLogAction;
thread = new Thread(Run);
thread.SetApartmentState(ApartmentState.STA);
thread.IsBackground = true;
thread.Name = "OpenVisionLab.Init";
}
public FormInit Form
{
get
{
formReady.Wait();
return form;
}
}
public static StartupSplashScreen Start(string versionText, Action<string> versionLogAction)
{
StartupSplashScreen splashScreen = new StartupSplashScreen(versionText, versionLogAction);
splashScreen.thread.Start();
splashScreen.formReady.Wait();
return splashScreen;
}
public void Dispose()
{
Close();
formReady.Dispose();
}
private void Run()
{
try
{
form = new FormInit
{
VersionText = versionText,
VersionLogAction = versionLogAction
};
form.Shown += (sender, e) => formReady.Set();
form.FormClosed += (sender, e) => Application.ExitThread();
Application.Run(form);
}
catch
{
formReady.Set();
}
}
private void Close()
{
formReady.Wait();
if (form == null || form.IsDisposed)
{
return;
}
try
{
form.BeginInvoke(new System.Windows.Forms.MethodInvoker(() =>
{
if (!form.IsDisposed)
{
form.Close();
}
}));
}
catch
{
}
}
}
}
}