How can I prevent launching my app multiple times?

后端 未结 10 1848
北荒
北荒 2020-12-13 18:42

I deployed my C# WinForms application using ClickOnce installation. Everything works fine with it (after a lot of work) :), but now I\'m facing a problem:

Whenever

10条回答
  •  醉酒成梦
    2020-12-13 18:57

    At program startup check if same process is already running:

    using System.Diagnostics;
    
    static void Main(string[] args)
    {
       String thisprocessname = Process.GetCurrentProcess().ProcessName;
    
       if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
          return;           
    }
    

提交回复
热议问题