This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
51 lines (45 loc) · 1.65 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
51
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace MapleRIL
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private Mutex singleInstanceMutex = null;
private string appMutexId = @"NexerqDev-MapleRIL";
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
#if !DEBUG
e.Handled = true;
MessageBox.Show("A fatal error has occured in MapleRIL. Please screenshot and report this error to Nexerq via Discord, or, with some extra details, submit an issue to the GitHub repository (nicholastay/MapleRIL)!\n\n" + e.Exception.ToString(), "MapleRIL - Fatal Exception", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(1);
#endif
}
protected override void OnStartup(StartupEventArgs e)
{
bool mutexCreated;
singleInstanceMutex = new Mutex(true, appMutexId, out mutexCreated);
if (!mutexCreated)
{
MessageBox.Show("MapleRIL is already running. Only one instance is allowed at a time.");
Environment.Exit(1);
return;
}
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
if (singleInstanceMutex != null)
singleInstanceMutex.ReleaseMutex();
base.OnExit(e);
}
}
}