Initial commit: BMS CAN monitor

This commit is contained in:
acetaffy
2026-09-16 13:26:51 +08:00
commit 2b92f10a0c
23 changed files with 965 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
using System.Threading;
using System.Windows;
namespace BmsMonitor.App;
public partial class App : Application
{
private Mutex? _singleInstanceMutex;
private bool _ownsMutex;
protected override void OnStartup(StartupEventArgs e)
{
_singleInstanceMutex = new Mutex(true, "Local\\BmsMonitor.ReadOnly.SingleInstance", out _ownsMutex);
if (!_ownsMutex)
{
MessageBox.Show("BMS Monitor 已经在运行。请关闭已有窗口后再启动。", "程序已运行",
MessageBoxButton.OK, MessageBoxImage.Information);
Shutdown();
return;
}
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
if (_ownsMutex) _singleInstanceMutex?.ReleaseMutex();
_singleInstanceMutex?.Dispose();
base.OnExit(e);
}
}