In this trick, we will try to understand how we can ensure that only one instance of a C# program is running on a computer. I have also created a simple video for the trick below. So you can either see the video or read the below textual description.
First, import the
Second, use the process object to get the process name.
string strProcessName = Process.GetCurrentProcess().ProcessName;
Find the process name in the current process collection.
Process Oprocesses = Process.GetProcessesByName(strProcessName);
Depending on the process count, make your decision.
if (Oprocesses.Length > 1)
MessageBox.Show("The application is already running");