add check if application is running

This commit is contained in:
Jakob 2019-11-09 19:48:21 +01:00
parent bcf11b4d79
commit 802b2daaaf
2 changed files with 19 additions and 6 deletions

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Shapes;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -26,6 +25,11 @@ namespace EnvyUpdate
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
if (Util.IsProcessOpen("EnvyUpdate"))
{
MessageBox.Show("Application is already running.");
System.Environment.Exit(1);
}
if (!Directory.Exists(appdata)) if (!Directory.Exists(appdata))
{ {
Directory.CreateDirectory(appdata); Directory.CreateDirectory(appdata);
@ -39,7 +43,7 @@ namespace EnvyUpdate
else else
{ {
MessageBox.Show("No NVIDIA GPU found. Application will exit."); MessageBox.Show("No NVIDIA GPU found. Application will exit.");
System.Windows.Application.Current.Shutdown(); System.Environment.Exit(255);
} }
if (File.Exists(appdata + "nvidia-update.txt")) if (File.Exists(appdata + "nvidia-update.txt"))
{ {

View file

@ -1,12 +1,9 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Management; using System.Management;
using System.Net;
using System.IO; using System.IO;
using IWshRuntimeLibrary; using IWshRuntimeLibrary;
using System.Diagnostics;
namespace EnvyUpdate namespace EnvyUpdate
{ {
@ -86,5 +83,17 @@ namespace EnvyUpdate
shortcut.TargetPath = targetFileLocation; shortcut.TargetPath = targetFileLocation;
shortcut.Save(); shortcut.Save();
} }
public static bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
} }
} }