From cf38013413f87adb9d505fc610706294d07fe298 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 12 Nov 2022 15:33:53 +0530 Subject: [PATCH] DnsServerSystemTrayApp.Program: updated code to support exit app option. --- DnsServerSystemTrayApp/Program.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/DnsServerSystemTrayApp/Program.cs b/DnsServerSystemTrayApp/Program.cs index b3b1d124..b791a61b 100644 --- a/DnsServerSystemTrayApp/Program.cs +++ b/DnsServerSystemTrayApp/Program.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2022 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -62,17 +62,31 @@ namespace DnsServerSystemTrayApp _app = new Mutex(true, MUTEX_NAME, out bool createdNewMutex); + bool exitApp = false; + if (!createdNewMutex) { - MessageBox.Show("Technitium DNS Server system tray app is already running.", "Already Running!", MessageBoxButtons.OK, MessageBoxIcon.Information); - return; + if (args.Length == 0) + { + MessageBox.Show("Technitium DNS Server system tray app is already running.", "Already Running!", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; + } + else + { + exitApp = true; + } } #endregion string configFile = Path.Combine(Path.GetDirectoryName(APP_PATH), "SystemTrayApp.config"); - Application.Run(new MainApplicationContext(configFile, args)); + MainApplicationContext mainApp = new MainApplicationContext(configFile, args, ref exitApp); + + if (exitApp) + mainApp.Dispose(); + else + Application.Run(mainApp); } public static void RunAsAdmin(string args)