限制只啓動一個程序實例

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace OneCase
{
    
static class Program
    
{
        
/// <summary>
        
/// 應用程序的主入口點。
        
/// </summary>

        [STAThread]
        
static void Main()
        
{
            
bool isNew;
            Mutex m 
= new Mutex(true"MyApp"out isNew);

            
if (isNew)
            
{
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(
false);
                Application.Run(
new Form1());
            }

            
else
            
{
                MessageBox.Show(
"已經存在一個程序實例!");
                Application.Exit();
            }

        }

    }

}
 
發佈了30 篇原創文章 · 獲贊 2 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章