Bhavya

Code -> Break -> Fix -> Blog

Restrict multiple instance of your Windows Application

Leave a comment


static class MutexClass
{
private static Mutex myMutex;

public static bool IsApplicationRunning()
{
if(Mutex.TryOpenExisting("singleApplicationMutex",out myMutex))
{
return true;
}

myMutex = new Mutex(true, "singleApplicationMutex");

return false;
}
}

class MainClass
{
public static void Main()
{
if (MutexClass.IsApplicationRunning())
{
Console.WriteLine("Application already running");
}
else
{
Console.WriteLine("Application started");

// Launch you application here.
}

Console.ReadLine();
}
}

Advertisements

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