2020年3月27日 星期五

C# 避免同樣的程式重複開啟

再Program.cs中先using System.Diagnostics;

再寫入程式碼

            string processName = Process.GetCurrentProcess().ProcessName;
            Process[] p = Process.GetProcessesByName(processName);

            if (p.Length > 1)
            {
                MessageBox.Show("已有同樣程式使用中");
                Environment.Exit(1);
            }

沒有留言:

張貼留言