Previous instance of an application in C#
How to check whether a previous instance of an application is already running in C#?
It is possible with C# to look for previous instances of an application. Here is a method.
private static bool IsPrevInstance()
{
//Find name of current process
string currentProcessName = Process.GetCurrentProcess ().ProcessName;
//Find the name of all processes having current process name
Process[] processesNamesCollection = Process.GetProcessesByName(currentProcessName);
//Check whether more than one process is running
if (processesNamesCollection.Length > 1)
return true;
else
return false;
}
Note: Process class is available in System.Diagnostics name space
It is possible with C# to look for previous instances of an application. Here is a method.
private static bool IsPrevInstance()
{
//Find name of current process
string currentProcessName = Process.GetCurrentProcess ().ProcessName;
//Find the name of all processes having current process name
Process[] processesNamesCollection = Process.GetProcessesByName(currentProcessName);
//Check whether more than one process is running
if (processesNamesCollection.Length > 1)
return true;
else
return false;
}
Note: Process class is available in System.Diagnostics name space
0 Comments:
Post a Comment
<< Home