Skip to content

Instantly share code, notes, and snippets.

@thedava
Created May 10, 2016 08:51
Show Gist options
  • Save thedava/f851d2c28d651d89485f1d9658dbb508 to your computer and use it in GitHub Desktop.
Save thedava/f851d2c28d651d89485f1d9658dbb508 to your computer and use it in GitHub Desktop.
C# Instance Detection
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