20240301_JSEQ_upperpc/MonitoringProgram/MonitoringProgram/Program.cs
XuMin aed71c76c6 新增程序:
1 用于监测江苏地震上位机软件的运行情况,在端口占用和程序异常崩溃的情况下,重新启动上位机软件;
2024-09-26 14:25:48 +08:00

35 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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());
}
}
}