C# Winforms: Disallow multiple instances of your application

I have found the following solution to disallow multiple instances of my WinForms application:

using System.Diagnostics;
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
     Process.GetCurrentProcess().Kill();
}

This works for me but I am not sure if this is the right mechanism. My gut feeling is that this can easily be dogded but I am not sure HOW. Anyone?

Advertisements

4 thoughts on “C# Winforms: Disallow multiple instances of your application

  1. You can run multiple instances of your application with this line of code, by making a copy of your .exe file and renaming it. Then Open It, and here it is 😉

  2. Pingback: C#: Disallow multiple instances of your application. The Mutex way. « Hash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s