Thursday 9 October 2008

Check if an instance of another app is open

The following method checks to see if an instance of a specific application is running.....

using System.Diagnostics;

private bool CheckIfPPlusOpen()
{
Process[] pApps = Process.GetProcesses();
bool bPPlus = false;
foreach (Process p in pApps)
{
if (p.ProcessName.Equals("P+Test"))
{
bPPlus = true;
}
}
if (!bPPlus)
{
GetPPlusAbsenceData();
}
else
{
MessageBox.Show("Please close P+ before refreshing the P+ data!", "Close P+", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return bPPlus;
}

No comments:

Free Hit Counter