-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
44 lines (40 loc) · 1.22 KB
/
App.xaml.cs
File metadata and controls
44 lines (40 loc) · 1.22 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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using UtilsNS;
namespace scripthea
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static System.Threading.Mutex _mutex = null;
protected override void OnStartup(StartupEventArgs e)
{
char k = Utils.isInVisualStudio ? 'E' : 'F';
_mutex = new System.Threading.Mutex(true, "{8F6F0AC4-B9A1-45fd-A8CF-73F04E6BDE8"+k+"}", out bool createdNew);
if (!createdNew) // another instance already running
{
if (Utils.isInVisualStudio) // if under development
{
if (Utils.ConfirmationMessageBox("Previous instance of Scripthea is already running.\n Close the current instance?")) Environment.Exit(0);
}
else // user case
{
Utils.TimedMessageBox("Previous instance of Scripthea is already running.", "Application halting!"); Current.Shutdown();
}
}
else Exit += CloseMutexHandler;
base.OnStartup(e);
}
protected virtual void CloseMutexHandler(object sender, EventArgs e)
{
_mutex?.Close();
}
}
}