Saturday, October 4, 2014

Creating Single Instance in Window application

9:41 AM - By azeheruddin khan 0

Step 1: Create a Window Application.
Step 2: Goto -> Program.cs file.
Step 3: Add System.Windows.Forms;
Step 4: Write below code in Main Method of Program.cs file.
Step 5: Build the Application -> Open Bin folder of your application -> Click on SingleInstance.exe


using System.Threading;
using System.Windows.Forms;

namespace SingleInstance
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>

        
        private static Mutex _Mutex;       

        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            bool blnCheckInstance;
            _Mutex = new Mutex(true, "SingleInstance", out blnCheckInstance);

            if (blnCheckInstance)
            {
                Application.Run(new HomeForm());
            }
            else
            {
                MessageBox.Show("Application already running.", Application.ProductName,
                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}







About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top