I want to replace cMyProcessName (in my example) programatic, i dont want to use a sting constant !
This is the code:
private const string cMyProcessName = "MyProcessName";
if (GetProcessCount(cMyProcessName) > 1)
{
System.Threading.Thread.Sleep(2000); //Give it some time (if just restarted)
//**************************************************************//
if (GetProcessCount(cMyProcessName) > 1)
{
MessageBox.Show("MyProcessName is already running. Exiting.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//**************************************************************//
}
public static int GetProcessCount(string processName)
{
Process[] ps = Process.GetProcessesByName(processName);
return ps.Length;
}