From 0f5937b38776665a35ff6dcef788461b5fa76321 Mon Sep 17 00:00:00 2001 From: kaso17 Date: Fri, 1 Dec 2017 10:28:19 +0100 Subject: [PATCH] JackettTray: check if it's already running fixes #2181 --- src/Jackett.Tray/Program.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Jackett.Tray/Program.cs b/src/Jackett.Tray/Program.cs index b902536cd..c19968879 100644 --- a/src/Jackett.Tray/Program.cs +++ b/src/Jackett.Tray/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; @@ -14,9 +15,21 @@ namespace JackettTray [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Main()); + var JacketTrayProcessName = Process.GetCurrentProcess().ProcessName; + var runningProcesses = Process.GetProcesses(); + var currentSessionID = Process.GetCurrentProcess().SessionId; + var sameAsThisSession = runningProcesses.Where(p => p.SessionId == currentSessionID); + var sameAsThisSessionJacketTray = sameAsThisSession.Where(p => p.ProcessName == JacketTrayProcessName); + if (sameAsThisSessionJacketTray.Any()) + { + MessageBox.Show("JackettTray is already running"); + } + else + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Main()); + } } } }