Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (83 loc) · 2.55 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (83 loc) · 2.55 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
using System;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Reflection;
using jColorPicker;
using jColorPicker.Utils;
static class Program
{
[STAThread]
static void Main()
{
if (!SingleInstance.Start())
{
MessageBox.Show("This program is already started, check your task bar.");
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
KeyCodeConverter.Start();
PreferenceManager.Start();
DatabaseManager.Start();
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
SingleInstance.Stop();
}
}
static public class SingleInstance
{
static Mutex mutex;
static public bool Start()
{
bool onlyInstance = false;
string mutexName = String.Format("Local\\{0}", ProgramInfo.AssemblyGuid);
// if you want your app to be limited to a single instance
// across ALL SESSIONS (multiple users & terminal services), then use the following line instead:
// string mutexName = String.Format("Global\\{0}", ProgramInfo.AssemblyGuid);
mutex = new Mutex(true, mutexName, out onlyInstance);
return onlyInstance;
}
static public void Stop()
{
mutex.ReleaseMutex();
}
}
static public class ProgramInfo
{
static public string AssemblyGuid
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
if (attributes.Length == 0)
{
return "bc59ee70-7768-4e47-b793-6c841eb71751";
}
return ((System.Runtime.InteropServices.GuidAttribute)attributes[0]).Value;
}
}
static public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase);
}
}
}