SyncLock Method  
 

Lock or unlock the server, synchronizing access to shared data for all active client sessions.

This method has been deprecated and may not be included in future versions of the control.

Syntax

object.SyncLock( Enable )

Parameters

Enable
A boolean value which specifies if the server should be locked.

Return Value

A value of zero is returned if the operation was successful, otherwise a non-zero error code is returned which indicates the cause of the failure.

Remarks

The SyncLock method is used to lock or unlock the server, enabling the application to synchronize access to shared data.

If the Enable argument is True, the server will enter a locked state where only the current thread may interact with the server and the clients that are connected to it. While a server is locked, all other threads will block when they attempt to perform a network operation. When the server is unlocked, the blocked threads will resume normal execution.

If the Enable argument is False, the server lock will be released and any blocked threads will resume execution. Only one server may be locked at any one time, and only the thread which established the lock can unlock the server.

This method should be used carefully, and a server should never be left in a locked state for an extended period of time. It is meant to be used when the application updates a global data structure and it must prevent any other threads from performing a network operation during the update. Only one server can be locked at any one time, and once a server has been locked, it can only be unlocked by the same thread.

The program should always check the return value from this method, and should never assume that the lock has been established. If more than one thread attempts to lock a server at the same time, there is no guarantee as to which thread will actually establish the lock. If a potential deadlock situation is detected, this method will fail.

Every time the SyncLock method is called with the Enable argument set to True, an internal lock counter is incremented, and the lock will not be released until the lock count drops to zero. This means that each call to the method must be matched by an equal number of calls with the Enable argument set to False. Failure to do so will result in the server becoming non-responsive as it remains in a locked state. 

See Also

IsLocked Property