static void Main()

{
// get the name of our process
string proc=Process.GetCurrentProcess().ProcessName;
// get the list of all processes by that name
Process[] processes=Process.GetProcessesByName(proc);
// if there is more than one process
if (processes.Length > 1)

{
MessageBox.Show("Application is already running");
return;
} else
Application.Run(new Form1());
}

{
// get the name of our process
string proc=Process.GetCurrentProcess().ProcessName;
// get the list of all processes by that name
Process[] processes=Process.GetProcessesByName(proc);
// if there is more than one process
if (processes.Length > 1)
{
MessageBox.Show("Application is already running");
return;
} else
Application.Run(new Form1());
}
本文提供了一个简单的C#示例,展示了如何检查当前运行的应用程序是否已存在另一个实例。通过获取当前进程名称并查找相同名称的其他进程,如果发现不止一个实例,则会弹出提示消息。
1017

被折叠的 条评论
为什么被折叠?



