C#: How to allow only one instance of an application to run.

Giugno 29th, 2007

Description: Add this method in the Program.cs and call this function within the main() function.

Link: http://www.codekeep.net/snippets/1cf891dd-fb96-4efa-9186-9ab8cdfd57e8.aspx

 private static void onlyOneAppInstance()
        {
            Mutex appSingleton = new System.Threading.Mutex(false, "SingleInstanceRegistroActivo");
            if(appSingleton.WaitOne(0, false))
                Application.Run(new Login());
            appSingleton.Close();
        }

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.