Is there a lock statement in VB.NET?

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

35579 次浏览

Yes, it's called SyncLock

Yes, the SyncLock statement.

For example:

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


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

It is called SyncLock example:

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