再次启动同一个应用程序的问题

dewy61786 2003-09-17 12:27:51
已经启动了一个应用程序,在没有关闭之前再启动这个程序,这时应该禁止应用程序的再启动,该如何做???希望给出具体代码!!!谢谢!
...全文
45 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
_weiKun_ 2003-09-17
  • 打赏
  • 举报
回复
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName (current.ProcessName);
//Loop through the running processes in with the same name

foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
{
//Return the other process instance.
return process;
}
}
}
//No other instance was found, return null.
return null;
}

rouser 2003-09-17
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2236/2237000.xml?temp=.9667017

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧