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

namespace TestSingleProcessInSameOS
{
    
static class Program
    {
        
/// <summary>
        
/// 应用程序的主入口点。
        
/// </summary>
        [STAThread]
        
static void Main()
       {
           
bool ret;
           System.Threading.Mutex mutex 
= new System.Threading.Mutex(true, Application.ProductName, out ret);
           
if (ret)
           {
               System.Windows.Forms.Application.EnableVisualStyles();
               System.Windows.Forms.Application.DoEvents();
               System.Windows.Forms.Application.Run(
new Form1());   
               mutex.ReleaseMutex();
           }
           
else
           {
               MessageBox.Show(
null"有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
               Application.Exit();
//退出程序   
           }



        }
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案