Introduction
Create instance for Process class to store the current running process. GetCurrentProcess() will create a new process component and assign it to the currnet process we are running. Create another instance for Process class.Check whether already the same process in running using GetProcessesByName method.GetProcessesByName method creates an array of process and associates them with all the process component that share the specified process name. Check if the length of the array object is greater than one.If it is then current process is already instantiated. Otherwise allow the process to run.
static void Main()
{
Process ThisProcess = Process.GetCurrentProcess();
Process [] AllProcesses = Process.GetProcessesByName(ThisProcess.ProcessName);
if (AllProcesses.Length > 1)
{
MessageBox.Show(ThisProcess.ProcessName + " is already running",
ThisProcess.ProcessName,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}else {
Application.Run(new MainForm());
}
}