-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
50 lines (42 loc) · 1.25 KB
/
App.xaml.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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace WindowsConsoleOS
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static Mutex mutex = null;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
string mutexName = @"Global\WindowSelector-EFA78C99-1FA0-4FDB-918D-3145454E9EFD";
bool createdNew;
mutex = new Mutex(true, mutexName, out createdNew);
if (!createdNew)
{
// If the mutex already exists, it means another instance of the application is already running.
//MessageBox.Show("An instance of the application is already running.");
Application.Current.Shutdown();
return;
}
}
protected override void OnExit(ExitEventArgs e)
{
if (mutex != null)
{
mutex.ReleaseMutex();
}
base.OnExit(e);
}
}
}