![]() This is true even in the case of an unhandled exception.įramework Calls. Because of this, the SyncLock block guarantees release of the lock, no matter how you exit the block. A SyncLock block behaves like a Try.Finally construction in which the Try block acquires an exclusive lock on lockobject and the Finally block releases it. This protects data maintained by the individual instance.Īcquisition and Release. If lockobject is an instance variable (not Shared), the lock prevents a thread running in the current instance from executing the SyncLock block at the same time as another thread in the same instance. This protects data that is shared among all the instances. If lockobject is a Shared variable, the exclusive lock prevents a thread in any instance of the class from executing the SyncLock block while any other thread is executing it. When another thread reaches the SyncLock statement, it does not acquire a lock until the first thread executes the End SyncLock statement. ![]() When a thread reaches the SyncLock statement, it evaluates the lockobject expression and suspends execution until it acquires an exclusive lock on the object returned by the expression. You can't use the Await operator in a SyncLock block. The mechanism requires that the lock object remain unchanged. You cannot change the value of lockobject while executing a SyncLock block. You must create the lock object before you use it in a SyncLock statement. The value of lockobject cannot be Nothing. You cannot branch into a SyncLock block from outside the block. If the statements that manipulate the data must go to completion without interruption, put them inside a SyncLock block.Ī statement block protected by an exclusive lock is sometimes called a critical section. The most common use of SyncLock is to protect data from being updated by more than one thread simultaneously. SyncLock prevents each thread from entering the block until no other thread is executing it. ![]() The SyncLock statement ensures that multiple threads do not execute the statement block at the same time. Block of statements that are to execute when the lock is acquired. Expression that evaluates to an object reference. Acquires an exclusive lock for a statement block before executing the block. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |