forked from openhardwaremonitor/openhardwaremonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (75 loc) · 2.75 KB
/
Program.cs
File metadata and controls
87 lines (75 loc) · 2.75 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
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using OpenHardwareMonitor.GUI;
namespace OpenHardwareMonitor {
public static class Program {
static Mutex mutex = new Mutex(true, "{3661aef2-95dc-433e-932c-2e06112d24ec}");
[STAThread]
public static void Main() {
if (!IsNetFrameworkInstalled())
Environment.Exit(0);
if (!mutex.WaitOne(TimeSpan.Zero, true)) {
MessageBox.Show("Another instance of the application is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Environment.Exit(0);
}
#if !DEBUG
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
#endif
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var form = new MainForm()) {
form.FormClosed += (sender, e) => Application.Exit();
Application.Run();
mutex.ReleaseMutex();
}
}
private static bool IsNetFrameworkInstalled() {
Type type;
try {
type = TryGetDefaultDllImportSearchPathsAttributeType();
} catch (TypeLoadException) {
MessageBox.Show(
"This application requires the .NET Framework 4.8 or a later version.\n" +
"Please install the latest .NET Framework. For more information, see\n\n" +
"https://dotnet.microsoft.com/download/dotnet-framework",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return type != null;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static Type TryGetDefaultDllImportSearchPathsAttributeType() {
return typeof(DefaultDllImportSearchPathsAttribute);
}
private static void ReportException(Exception e) {
var form = new CrashForm {
Exception = e
};
form.ShowDialog();
}
public static void Application_ThreadException(object sender,
ThreadExceptionEventArgs e) {
try {
ReportException(e.Exception);
} catch {
} finally {
Application.Exit();
}
}
public static void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs args) {
try {
if (args.ExceptionObject is Exception e)
ReportException(e);
} catch {
} finally {
Environment.Exit(0);
}
}
}
}