iburlakov
iburlakov

Reputation: 4232

Is there a lock statement in VB.NET?

Does VB.NET have the equivalent of C#'s lock statement?

Upvotes: 82

Views: 37807

Answers (3)

CSharpAtl
CSharpAtl

Reputation: 7512

It is called SyncLock example:

Sub IncrementWebCount()
    SyncLock objMyLock
        intWebHits += 1
        Console.WriteLine(intWebHits)
    End SyncLock
End Sub

Upvotes: 31

Jon Skeet
Jon Skeet

Reputation: 1500535

Yes, the SyncLock statement.

For example:

// C#
lock (someLock)
{
    list.Add(someItem);
}

// VB
SyncLock someLock
    list.Add(someItem)
End SyncLock

Upvotes: 119

Chris Dunaway
Chris Dunaway

Reputation: 11216

Yes, it's called SyncLock

Upvotes: 2

Related Questions