[DllImport("coredll.dll", SetLastError=true)]
public static extern int CreateMutex(int lpMutexAttributes, int bInitiaOwner, string lpName);
[DllImport("coredll.dll")]
public static extern int GetLastError();
const long ERROR_ALREADY_EXISTS = 183;
It should be used in conjunction with GetLastError() to check the application already existed in the process list.
private static bool CheckInstance()
{
CreateMutex(0, 1, "<Application Name>"); // to be replaced by the name of your application
int lastError = GetLastError();
if (lastError == ERROR_ALREADY_EXISTS)
{
return true;
}
return false;
}