.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Run Only One Copy Of Application

Posted By:Ravi Ranjan Kumar       Posted Date: June 04, 2011    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

This Article allow you to run only one Instance of application at a time.

This article allow you to run only one instance of your application at a time.Many time we have requirement that we need to run only one instance of application at a time. If you have same requirement then in that case this article might be useful for you.
Here you will learn how to handle only one instance of application by using Mutex

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
namespace OnlyOneInstance
    static class Program

        static void Main()
            bool instantiated;
          /* If instantiated is true, this is the first instance of the application; else, another instance is running. */
            Mutex mutex = new Mutex(true, "UniqueID", out instantiated);
            if (!instantiated)
                MessageBox.Show("Already Running");
            Application.Run(new Form1());
You can download Source Code at given below 
After downloading Go to bin directory and then Click on OnlyOneInstance.exe file twice, you will see a message box which stated Program "Already Running". 
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend