80

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

gonzobrains
  • 7,856
  • 14
  • 81
  • 132
iburlakov
  • 4,164
  • 7
  • 38
  • 40

3 Answers3

116

Yes, the SyncLock statement.

For example:

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

// VB
SyncLock someLock
    list.Add(someItem)
End SyncLock
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
31

It is called SyncLock example:

Sub IncrementWebCount()
    SyncLock objMyLock
        intWebHits += 1
        Console.WriteLine(intWebHits)
    End SyncLock
End Sub
CSharpAtl
  • 7,374
  • 8
  • 39
  • 53
2

Yes, it's called SyncLock

Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48