Program.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Reflection;
namespace 收银系统
{
static class Program
{
//显示窗口
//[DllImport("user32.dll", EntryPoint = "ShowWindow")]
//static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[STAThread]
static void Main()
{
Process current = Process.GetCurrentProcess();//获取当前进程
Process[] processes = Process.GetProcessesByName(current.ProcessName);//获取与当前进程名称相同的所有进程
foreach (Process process in processes)//遍历同名进程
{
if (process.Id != current.Id)//如果此线程不是当前进程
{
if (process.MainModule.FileName == current.MainModule.FileName)//如果已经存在的进程的路径是当前进程的路径
{
//显示已经打开的进程的窗体和结束当前进程;
//注:重新显示窗体后打开的子对话框会被自动关闭!
//ShowWindow(process.MainWindowHandle, 6);//最小化
//ShowWindow(process.MainWindowHandle, 9);//显示
MessageBox.Show("不能重复运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;//结束本次启动
}
}
}
//显示主窗体
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
