标签:style blog http ar color 使用 sp for on
上文是在网上找的检测程序重复运行的类,但是感觉不是很好用,而且还使用了API,似乎完全没有必要,于是晚上自己写了一个函数,经过测试,在多用户下仍然可以检测到程序的多次运行。当然,如果程序改了名字还是可以再次运行,不过这种方式只怕没有什么太好的办法来,除非是在.NET环境或注册表中写入一些标志,但似乎也没有必要。
if (AppInstance()) { MessageBox.Show("警告:程序正在运行中! 请不要重复打开程序!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } public static bool AppInstance() { Process[] MyProcesses = Process.GetProcesses(); int i = 0; foreach (Process MyProcess in MyProcesses) { if (MyProcess.ProcessName == Process.GetCurrentProcess().ProcessName) { i++; } } return (i > 1) ? true : false; }
其实就在是进程中检查进程名,如果多于一个,则返回TRUE
出处:http://blog.csdn.net/lanman/article/details/3655972
标签:style blog http ar color 使用 sp for on
原文地址:http://www.cnblogs.com/mq0036/p/4138470.html