欢迎光临
我们一直在努力

防止同一个程序多次运行。 [VB.NET]-.NET教程,VB.Net语言

建站超值云服务器,限时71元/月

防止同一个程序多次运行。

*****************方法一:防止程序多次打开*****************

函数名: isinstancerunning

功 能: 判断工程是否已运行

参 数: 无

返回值: true 已运行 false 未运行

*******************************************************

public function isinstancerunning() as boolean

dim current as process = system.diagnostics.process.getcurrentprocess()

dim processes as process() = system.diagnostics.process.getprocessesbyname(current.processname)

loop through the running processes in with the same name

dim p as process

for each p in processes

ignore the current process

if p.id <> current.id then

make sure that the process is running from the exe file.

if system.reflection.assembly.getexecutingassembly().location.replace("/", "\") = current.mainmodule.filename then

return the other process instance.

return true

end if

end if

next

no other instance was found, return null.

return false

end function runninginstance

*****************方法二:防止程序多次打开*****************

imports system.diagnostics

if ubound(process.getprocessesbyname(process.getcurrentprocess.processname)) _

> 0 then eixt sub

process.getcurrentprocess.processname 获取当前运行程序的名称。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 防止同一个程序多次运行。 [VB.NET]-.NET教程,VB.Net语言
分享到: 更多 (0)

相关推荐

  • 暂无文章