While I was developing Auto CCleaner I faced a problem with allowing only one instant of the application. I found many solutions (using mutex) and others, but it didn’t work or it was inefficient. What I needed is a simple, easy, and efficient method. Hence I used little help from .NET Process class as follow:
I added this block to initialize (load) function:
if (Process.GetProcessesByName(Application.ProductName).GetLength(0) >= 2)
MessageBox.Show("Only one instance of the app is allowed!");
Tada! Only a single instance is allowed now.
note: You need to add:
using System.Diagnostics; at the beginning of your