微信如何做积分商城网站,c2c电商网站,南京制作网站公司哪家好,wordpress内容函数有时候#xff0c;我们只能允许程序单实例运行#xff0c;以免程序运行出错。可以通过使用App.PrevInstance和系统级的Mutex等多种办法来实现。
代码如下#xff1a;
用户昵称: 留下些什么
个人简介: 一个会做软件的货代
CSDN网址#xff1a;https://blog.csdn.net/zezes…有时候我们只能允许程序单实例运行以免程序运行出错。可以通过使用App.PrevInstance和系统级的Mutex等多种办法来实现。
代码如下
用户昵称: 留下些什么
个人简介: 一个会做软件的货代
CSDN网址https://blog.csdn.net/zezese
电子邮箱31319180qq.comOption ExplicitPrivate Declare Function CreateMutex Lib kernel32.dll Alias CreateMutexA (ByRef lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
Private Declare Function CloseHandle Lib kernel32.dll (ByVal hObject As Long) As LongPrivate Const ERROR_ALREADY_EXISTS As Long 183Private Type SECURITY_ATTRIBUTESnLength As LonglpSecurityDescriptor As LongbInheritHandle As Long
End TypeDim hAppMutex As LongPrivate Sub Form_Initialize()方法1 使用 App.PrevInstance 这种办法只要EXE文件改个名字就可以运行多个实例。If App.PrevInstance ThenMsgBox 方法1 使用 App.PrevInstance 这种办法只要EXE文件改个名字就可以运行多个实例。EndEnd If方法2 使用系统级的Mutex改名字也没有用。If IsRunning ThenMsgBox 方法2 使用系统级的Mutex改名字也没有用。EndEnd IfEnd SubPrivate Function IsRunning() As BooleanDim sa As SECURITY_ATTRIBUTESsa.bInheritHandle 1sa.lpSecurityDescriptor 0sa.nLength Len(sa)hAppMutex CreateMutex(sa, 1, 31319180qq.com) 这里请使用自己的标志字符串或者 GUID 字符串If (Err.LastDllError ERROR_ALREADY_EXISTS) ThenCloseHandle hAppMutexIsRunning TrueEnd IfEnd FunctionPrivate Sub Form_Terminate()CloseHandle hAppMutex
End Sub