-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
46 lines (41 loc) · 1.24 KB
/
Copy pathProgram.cs
File metadata and controls
46 lines (41 loc) · 1.24 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
using System;
using System.Threading;
using System.Windows.Forms;
namespace ClipCleanTray
{
static class Program
{
// 用于确保单实例运行的互斥锁
private static Mutex _mutex;
/// <summary>
/// 应用程序的主入口点
/// </summary>
[STAThread]
static void Main()
{
// 检查是否已有实例在运行
bool createdNew;
_mutex = new Mutex(true, AppInfo.MutexName, out createdNew);
if (!createdNew)
{
// 已有实例在运行,退出
MessageBox.Show(AppInfo.DisplayName + " 已在运行中", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 使用托盘应用上下文运行(无主窗口)
Application.Run(new TrayApplicationContext());
}
finally
{
// 释放互斥锁
_mutex?.ReleaseMutex();
_mutex?.Dispose();
}
}
}
}