-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgram.cs
94 lines (80 loc) · 3.06 KB
/
Program.cs
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
#region Using statements
using System;
using System.Runtime;
using System.Threading;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
#endregion Using statements
namespace WeekNumber
{
internal class Program
{
#region Private variable to allow only one instance of application
private static readonly Mutex Mutex = new Mutex(true, "550adc75-8afb-4813-ac91-8c8c6cb681ae");
#endregion Private variable to allow only one instance of application
#region Application starting point
[STAThread]
private static void Main()
{
if (!Mutex.WaitOne(TimeSpan.Zero, true))
{
return;
}
WeekApplicationContext context = null;
try
{
Settings.RestoreBackupSettings();
Log.Init();
Settings.SetCultureInfoFromSystemOrSettings();
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
Log.Info = "=== Application started ===";
Log.Info = Application.ProductName + " version " + Application.ProductVersion;
NativeMethods.RefreshTrayArea();
SetGCSettings();
Application.EnableVisualStyles();
Application.VisualStyleState = VisualStyleState.ClientAndNonClientAreasEnabled;
Application.SetCompatibleTextRenderingDefault(false);
context = new WeekApplicationContext();
if (context?.Gui != null)
{
Application.Run(context);
}
}
finally
{
Log.Close("=== Application ended ===");
context?.Dispose();
Mutex.ReleaseMutex();
}
}
#endregion Application starting point
#region Private methods
/// <summary>
/// Configures garbarge collection settings
/// </summary>
private static void SetGCSettings()
{
Log.LogCaller();
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GCSettings.LatencyMode = GCLatencyMode.Batch;
}
#endregion Private methods that configures garbarge collection settings
#region Global unhandled Exception trap
/// <summary>
/// Catches all unhandled exceptions for the application
/// Writes the exception to the application log file
/// Terminates the application with exit code -1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = (Exception)e.ExceptionObject;
Log.Error = ex;
Message.Show(Resources.UnhandledException, ex);
Log.Close("=== Application ended ===");
Environment.Exit(1);
}
#endregion Global unhandled Exception trap
}
}