Allow only one instance of C# application

To allow only one once of your application to run, do the following:

namespace my_namespace
{
    class Program
    {
        static Mutex mutex;
 
        static void Main(string[] args)
        {
            bool fi;
            mutex = new Mutex(true, "my_app", out fi);
            if (!fi)
            {
                Environment.Exit(0);
            }
        }
    }
}
Categories: C# Tags: , , , ,
%d bloggers like this: