当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 防止同一个程序多次运行。 [VB.NET]

ASP.NET
.net基础知识错误注意二十二点知识
用.NET动态创建类的实例讲解
微软发布.NET Framework 3.5 SP1正式版
asp.net教程:HTTP状态码200,301,302
.NET 2.0中Hashtable快速查找的方法
在ASP.Net Ajax中调用WebService
asp.net 和 access 联合开发的分页类
ASP.NET 全局异常处理
用SQL语句完成SQL Server数据库的修复
.net 框架程序设计
ASP.NET结合XML编写计数器
ASP.NET水晶报表实现打印功能
Asp.Net中设计与使用水晶报表
防止ASP.NET按钮多次提交的办法
.NET开发事件处理的步骤
ASP.NET刷新页面的六种方法
Asp.net ajax实现任务提示页面
ASP.NET 2.0中XML数据的处理
ASP.NET中XML数据的处理
Jadu: 将 PHP 编译成 .NET

ASP.NET 中的 防止同一个程序多次运行。 [VB.NET]


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 91 ::
收藏到网摘: n/a

防止同一个程序多次运行。
'*****************方法一:防止程序多次打开*****************' 函数名: 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 FalseEnd Function 'RunningInstance

'*****************方法二:防止程序多次打开*****************Imports System.Diagnostics If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) _ > 0 Then Eixt Sub'Process.GetCurrentProcess.ProcessName 获取当前运行程序的名称。