-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
38 lines (32 loc) · 1.13 KB
/
Copy pathApp.xaml.cs
File metadata and controls
38 lines (32 loc) · 1.13 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
using System.Threading;
using System.Windows;
namespace PinBubble;
public partial class App : System.Windows.Application
{
private Mutex? _singleInstanceMutex;
private bool _ownsSingleInstanceMutex;
protected override void OnStartup(StartupEventArgs e)
{
_singleInstanceMutex = new Mutex(true, "PinBubble.SingleInstance", out bool isFirstInstance);
_ownsSingleInstanceMutex = isFirstInstance;
if (!isFirstInstance)
{
System.Windows.MessageBox.Show("PinBubble is already running. Only one instance can run at a time.",
"PinBubble",
MessageBoxButton.OK,
MessageBoxImage.Error);
Shutdown();
return;
}
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
if (_ownsSingleInstanceMutex)
_singleInstanceMutex?.ReleaseMutex();
_singleInstanceMutex?.Dispose();
_singleInstanceMutex = null;
_ownsSingleInstanceMutex = false;
base.OnExit(e);
}
}