Locks the object to gain access to it.
[ bLocked = ] Object.Lock
The Lock method syntax has the following parts:
|
Name |
Type |
Description |
|
Object |
ACriticalSection |
ACriticalSection object |
|
bLocked |
Bool |
A boolean expression that specifies whether the object is locked or unlocked. |
bLocked can be one of the following:
|
Value |
Description |
|
True * |
The ACriticalSection object is locked. |
|
False |
The ACriticalSection object is not locked. |
This member function locks the critical section object. You can make multiple lock calls on the same thread, but the Unlock member function must be called a corresponding number of times before the object is unlocked. If the object is locked by another thread, the Lock member function blocks until either the object is released or a "possible deadlock" exception occurs.
Unlike the Lock method of an AMutex object, the Lock method of an ACriticalSection does not have a timeout period.
The following example uses a CriticalSection object to allow one thread at the time to modify data or some other controlled resources:
if (csCriticalSection1.Lock)
! Access a shared resource
m_bSharedData=True
! Remember to Unlock the CriticalSection object to allow other threads to access the shared resources
csCriticalSection.Unlock
endif