See the examples for alternatives.ĮDIT 1: Just saw your comment that you have got a console application. No other instance was found, return null.
If (Assembly.GetExecutingAssembly().Location. Make sure that the process is running from the exe file. Loop through the running processes in with the same name So, here we have discussed few best methods to fix ‘Another instance is running’ error message. So, users need to close and kill the running process to fix the error message. Process processes = Process.GetProcessesByName (current.ProcessName) Well, Another instance of any particular software is running means the installer is already there on the background. Process current = Process.GetCurrentProcess() MessageBox.Show('An instance of the application is already running.') Mutex mutex = new (false, 'MyUniqueMutexName') Īpplication.SetCompatibleTextRenderingDefault(false) It's not sure what you mean with 'the program', but if you want to limit your application to one instance then you can use a Mutex to make sure that your application isn't already running. Which will kill the currently loading process instantly. OR if ((System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1) ().Kill() This works for any application (any name) and will become true if there is another instance running of the same application.Įdit: To fix your needs you can use either of these: if ((System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1) return įrom your Main method to quit the method.
var exists = (System.IO.Path.GetFileNameWithoutExtension(().Location)).Count() > 1