Force Single Instance with Mutex handling restart application

前端 未结 4 1989
[愿得一人]
[愿得一人] 2021-01-25 12:04

I have a problem when i want use mutex to force single instance of my program.

I a winform App with a WebBrowser Control. I need to autorestart if certain conditions ar

4条回答
  •  臣服心动
    2021-01-25 12:16

    I do:

        bool onlyInstance = false;
            mutex = new System.Threading.Mutex(true, "qFluid", out onlyInstance);
            int cntrSec = 0;
            //per far funzionare restart ,aspetto per 3 sec per vedere se va via servizio 
            while (!onlyInstance & cntrSec < 3)
            {
                System.Threading.Thread.Sleep(1000);
                cntrSec += 1;
            }
    
            if (!onlyInstance)
            {
                Xceed.Wpf.Toolkit.MessageBox.Show("The application is already arunning");
                App.Current.Shutdown();
            }
    

提交回复
热议问题