Fix close all

This commit is contained in:
2026-01-20 09:50:56 +01:00
parent 841490c906
commit 7fb573a8d9

View File

@@ -53,22 +53,6 @@ namespace EveOPreview.Presenters {
this.View.IconName = this._configuration.IconName;
}
private void Activate() {
this._suppressSizeNotifications = true;
this.LoadApplicationSettings();
this.View.SetDocumentationUrl(MainFormPresenter.FORUM_URL);
this.View.SetVersionInfo(this.GetApplicationVersion());
if (this._configuration.MinimizeToTray) {
this.View.Minimize();
}
// Initialize the tray profile menu
this.UpdateTrayProfileMenu();
this._mediator.Send(new StartService());
this._suppressSizeNotifications = false;
}
private void UpdateTrayProfileMenu() {
var profiles = this._profileManager.GetAvailableProfiles();
// Get the profile for this specific instance
@@ -309,36 +293,34 @@ namespace EveOPreview.Presenters {
private const string CLOSE_ALL_EVENT_NAME = "EVE-O-Preview_CloseAllEvent";
private static System.Threading.EventWaitHandle _closeAllEvent;
private static bool _closeAllListenerInitialized = false;
private void CloseAllInstances() {
// Signal all instances to close
try {
if (_closeAllEvent == null) {
// Create or open the named event
bool created;
_closeAllEvent = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, CLOSE_ALL_EVENT_NAME, out created);
if (!created) {
_closeAllEvent = System.Threading.EventWaitHandle.OpenExisting(CLOSE_ALL_EVENT_NAME);
}
if (_closeAllEvent == null) {
bool created;
_closeAllEvent = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, CLOSE_ALL_EVENT_NAME, out created);
if (!created) {
_closeAllEvent = System.Threading.EventWaitHandle.OpenExisting(CLOSE_ALL_EVENT_NAME);
}
// Signal all instances to close
_closeAllEvent.Set();
// Give time for signal to propagate
System.Threading.Thread.Sleep(100);
// Reset the event
_closeAllEvent.Reset();
} catch {
// Ignore if event creation fails
}
_closeAllEvent.Set();
// Give time for signal to propagate to other instances
// DO NOT reset - let each instance handle its own exit
System.Threading.Thread.Sleep(500);
// Close this instance
this.ExitApplication();
Environment.Exit(0);
}
static MainFormPresenter() {
private void InitializeCloseAllListener() {
if (_closeAllListenerInitialized) {
return;
}
_closeAllListenerInitialized = true;
// Initialize the close all event listener on app startup
System.Threading.Thread listenerThread = new System.Threading.Thread(() => {
try {
@@ -348,21 +330,13 @@ namespace EveOPreview.Presenters {
closeEvent = System.Threading.EventWaitHandle.OpenExisting(CLOSE_ALL_EVENT_NAME);
}
// Wait for the close all signal
while (true) {
try {
closeEvent.WaitOne();
closeEvent.Reset();
// Wait for the close all signal (one-time wait, then exit)
closeEvent.WaitOne();
// Close this instance
System.Windows.Forms.Application.Exit();
break;
} catch {
// Ignore errors and continue waiting
}
}
// Force immediate exit - no marshaling needed since we're terminating the process
Environment.Exit(0);
} catch {
// If event creation fails, just exit
throw;
}
}) {
IsBackground = true,
@@ -370,5 +344,24 @@ namespace EveOPreview.Presenters {
};
listenerThread.Start();
}
private void Activate() {
// Initialize the close all listener on first activation
this.InitializeCloseAllListener();
this._suppressSizeNotifications = true;
this.LoadApplicationSettings();
this.View.SetDocumentationUrl(MainFormPresenter.FORUM_URL);
this.View.SetVersionInfo(this.GetApplicationVersion());
if (this._configuration.MinimizeToTray) {
this.View.Minimize();
}
// Initialize the tray profile menu
this.UpdateTrayProfileMenu();
this._mediator.Send(new StartService());
this._suppressSizeNotifications = false;
}
}
}