Skip to content

Commit

Permalink
Better error message when other driver processes are running in the b…
Browse files Browse the repository at this point in the history
…ackground
  • Loading branch information
hawku committed Dec 10, 2018
1 parent 225d328 commit 90370cb
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions TabletDriverGUI/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -50,7 +51,7 @@ public App()
}

//
// Check other tablet driver processes
// Other tablet driver processes
//
string[] tabletDriverProcessNames =
{
Expand All @@ -72,34 +73,53 @@ public App()

};


//
// Find driver processes
//
processes = Process.GetProcesses();
List<Process> foundProcesses = new List<Process>();
foreach (Process process in processes)
{
foreach (string processName in tabletDriverProcessNames)
{
if (process.ProcessName.ToLower() == processName.ToLower())
{
try
{
process.Kill();
Thread.Sleep(100);
}
catch (Exception)
{
MessageBox.Show(
"You have other tablet driver processes running in the background:\n " +
string.Join("\n ", tabletDriverProcessNames) +
"\n\nPlease shutdown those before starting the GUI!",
"Error!", MessageBoxButton.OK, MessageBoxImage.Error
);
instanceMutex.ReleaseMutex();
Shutdown();
return;
}
foundProcesses.Add(process);
}
}
}

//
// Try to kill driver processes
//
foreach (Process process in foundProcesses)
{
try
{
process.Kill();
Thread.Sleep(100);
}
catch (Exception)
{
string processNames = "";
foreach (Process p in foundProcesses)
{
processNames += "- " + p.ProcessName + ".exe\n ";
}

MessageBox.Show(
"You have other driver processes running:\n " +
processNames +
"\nPlease shutdown those before starting this driver!",
"TabletDriverGUI - Error!", MessageBoxButton.OK, MessageBoxImage.Error
);
instanceMutex.ReleaseMutex();
Shutdown();
return;
}
}


MainWindow mainWindow = new MainWindow();
mainWindow.Show();
Expand Down

0 comments on commit 90370cb

Please sign in to comment.