g***@hotmail.com
2005-11-16 18:08:41 UTC
I have a global variable sMutexName which stores the name of the mutex
like you did.
The 1st instance creates the mutex.
CreateMutex(sa, 0&, sMutexName) 'Owner flag is 0, so it will not own
the mutex
where sa is SECURITY_ATTRIBUTES
with sa.nLength = Len(sa)
sMutexName = lpName ' lpName is the name for the mutex
The 2nd instance opens the mutex and waits to grab the mutex.
OpenMutex(SYNCHRONIZE, 0&, sMutexName)
WaitForSingleObject(sMutexName, lTimeOut) 'lTimeOut is currently set to
100
Then it releases the mutex with
ReleaseMutex(sMutexName)
If bInitialOwner Then
Call CloseHandle(sMutexName)
End If
But the form is not unloaded (it stays).
3rd instance is trying to do the same thing as the 2nd one AFTER the
2nd releases mutex. The 3rd instance keeps getting timeout at the
WaitForSingleObject call. Now what's causing the 3rd instance getting
timeout from
WaitForSingleObject call? It succeeds in OpenMutex. I am
confused. Anyone can explain this scenario? Thanks.
like you did.
The 1st instance creates the mutex.
CreateMutex(sa, 0&, sMutexName) 'Owner flag is 0, so it will not own
the mutex
where sa is SECURITY_ATTRIBUTES
with sa.nLength = Len(sa)
sMutexName = lpName ' lpName is the name for the mutex
The 2nd instance opens the mutex and waits to grab the mutex.
OpenMutex(SYNCHRONIZE, 0&, sMutexName)
WaitForSingleObject(sMutexName, lTimeOut) 'lTimeOut is currently set to
100
Then it releases the mutex with
ReleaseMutex(sMutexName)
If bInitialOwner Then
Call CloseHandle(sMutexName)
End If
But the form is not unloaded (it stays).
3rd instance is trying to do the same thing as the 2nd one AFTER the
2nd releases mutex. The 3rd instance keeps getting timeout at the
WaitForSingleObject call. Now what's causing the 3rd instance getting
timeout from
WaitForSingleObject call? It succeeds in OpenMutex. I am
confused. Anyone can explain this scenario? Thanks.