35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
|
||
namespace MonitoringProgram
|
||
{
|
||
internal static class Program
|
||
{
|
||
/// <summary>
|
||
/// 应用程序的主入口点。
|
||
/// </summary>
|
||
[STAThread]
|
||
static void Main()
|
||
{
|
||
Application.EnableVisualStyles();
|
||
Application.SetCompatibleTextRenderingDefault(false);
|
||
Process[] proccess = Process.GetProcesses();//获取所有进程
|
||
string strCaCuProcessName = "MonitoringProgram";//当前程序名
|
||
foreach (var pr in proccess)
|
||
{
|
||
if (pr.ProcessName == strCaCuProcessName && pr.Id != Process.GetCurrentProcess().Id)
|
||
{
|
||
//当前程序名相等且进程ID不一致,不加进程ID程序起不来(这时候程序已经运行着)
|
||
Environment.Exit(0);
|
||
}
|
||
}
|
||
Application.Run(new Form1());
|
||
}
|
||
|
||
}
|
||
}
|