Single instance of C# application
The System.Diagnostics namespace provides classes that allow you to interact with system processes, event logs, and performance counters. In order to determine if there are other instances of a C# application running in the system , we have to get a list of all the processes running in the system and check if an instance of the application is in the list or not.
The Process class provides functionality to track system processes in a system and to start and stop system processes. Process.GetProcessesByName to create an array of new Process components and associate them with all the process resources that are running the same executable file on the local computer.
The above code _process array receiving all the associated processes. If the _process array contains more than one instance , then we should clear the instance already exist.