c# mutex를 이용한 중복실행 방지
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
|
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main(string[] args)
{
{
bool createdNew;
Mutex dup = new Mutex(true, "SMC_Server", out createdNew);
if (createdNew)
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new simWorksMain());
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
MessageBox.Show("Server Open Error!! Already running");
return;
}
}
}
}
|
Mutex 생성시 이름이 키 입니다.
같은 이름의 Mutex는 생성되지 않기 때문에 중복실행을 검사할 수 있습니다.
댓글
댓글 쓰기