Created
May 10, 2016 08:51
-
-
Save thedava/f851d2c28d651d89485f1d9658dbb508 to your computer and use it in GitHub Desktop.
C# Instance Detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
public class InstanceDetector | |
{ | |
protected Process GetCurrentProcess() | |
{ | |
return Process.GetCurrentProcess(); | |
} | |
protected Process[] GetRunningProcesses() | |
{ | |
return Process.GetProcesses(); | |
} | |
public bool IsAnotherInstanceRunning() | |
{ | |
var current = this.GetCurrentProcess(); | |
foreach (var process in this.GetRunningProcesses()) | |
{ | |
if (process.ProcessName == current.ProcessName && process.Id != current.Id) | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment