SyncLock Statement


SyncLock Statement

Syntax

     SyncLock lockObject        [code]     End SyncLock 


lockObject (required; any)

The variable or instance to be locked; it is used as a gatekeeper for the enclosed code


code (optional)

Any Visual Basic source code that needs to be protected from simultaneous use by separate threads

Description

The SyncLock statement prevents multiple threads of execution in the same process from accessing a block of code at the same time.

Usage at a Glance

  • lockObject cannot be set to Nothing.

  • If lockObject is a shared object, all instances with access to that object are blocked until the SyncLock block exits. If it is an instance object, only threads using that particular instance are blocked.

  • You may not jump into a SyncLock block using a GoTo statement. You may jump out of the block; the lock will be properly released.

  • The SyncLock statement wraps a call to the .NET Framework's System.Threading.Monitor class's Enter and Exit methods.

  • .NET includes a number of other synchronization mechanisms, all of which are located in the System.Threading namespace.

Version Differences

The SyncLock statement is new to VB under .NET.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net