Usage of Mutex in c#

后端 未结 4 2026
陌清茗
陌清茗 2020-12-15 03:23

I am a bit new in threading in c# and on general, in my program I am using mutex to allow only 1 thread getting inside a critical section and f

4条回答
  •  自闭症患者
    2020-12-15 04:15

    Mutex use to identify run app instance.

     using (Mutex mutex = new Mutex(true, "app name", out createdNew))
                {
                    if (createdNew)//check app is already run
                    {
                        KillOthers();
                        StartApp();
                    }
                    else
                    {
                        MessageBox.Show("Another instance already running!");
                    }
                }
    

提交回复
热议问题