You can achieve it with the following code in your Main method of your Console Application
static void Main(string[] args)
{
bool isFirstInstance = true;
//Check whether an instance running already
Mutex mutex = new Mutex(true, "CurrentInstance", out isFirstInstance);
//If not first instance, then just reutn the control and do not process further
if (!isFirstInstance)
return;
else
{
//Continue the workflow and this is your first instance
Console.ReadKey();
}
}
Note: This will hold good, but the console window will get opened and closed if the instance is not the first one. This is the default behaviour and there is no direct way of suppressing this window. If you use the same logic for Windows it will not open any window becaause you will do the validation before the Application.Run is executed.