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

ASP.NET
浅析.NET 3.5 SP1中的JIT增强
在ASP.Net中实现RSA加密
浅析ASP.NET中C++和J#的混合应用
探讨ASP.NET MVC框架内置AJAX支持编程技术
Web开发模式的颠覆者:ASP.NET MVC
设计ASP.NET应用程序的七大绝招
浅谈Asp.net多层架构中的变量引用与传递
ASP.NET遍历配置文件的连接字符串
ASP.NET2.0中配置文件的加密与解密
Ja.Net:融合 Java 1.5 和 .NET
ASP.NET 2.0 中XML数据的处理
ASP.NET中备份SQL Server数据库的方法
asp.net/c#字符格式化
在.NET应用程序中进行Erlang风格的并行编程
Flex与.NET互操作:基于WebService的数据访问
asp.net 里 include UTF8 垃圾问题
让.Net程序脱离.Net Framework框架运行
.NET上执行多线程应该注意的两点
ASP.NET应该遵守的9条代码编写规范
.Net和Java的socket机制比较

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 89 ::
收藏到网摘: 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 获取当前运行程序的名称。