O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

SyncLock Statement

Syntax

SyncLock expression
...[ code ]
End SyncLock
expression (required; any reference type (class, module, interface, array, or delegate))

An expression yielding a single result that can be used to determine the accessibility of code

code (optional)

The code statements to which access is synchronized and that will be executed sequentially

Description

Prevents multiple threads of execution in the same process from accessing shared data or resources at the same time

Rules at a Glance

SyncLock blocks a thread’s access only if that thread belongs to the same object instance.

Programming Tips and Gotchas

  • The SyncLock statement wraps a call to the BCL’s System.Threading.Monitor. Enter method.

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

VB.NET/VB 6 Differences

The SyncLock statement is new to VB.NET. VB 6 provided the developer with no direct means of controlling threads of execution in applications or components.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required