VB中的SyncLock

Allows statements to be synchronized on a single expression.

SyncLock expression
...[ block ]
End SyncLock
Parts
expression
Required. A unique collection of operators and values that yield a single result.
block
Optional. The statements that will execute in sequence.
End SyncLock
Terminates a SyncLock procedure.
Remarks

The SyncLock statement ensures that multiple threads do not execute the same statements at the same time. When the thread reaches the SyncLock block, it evaluates the expression and maintains this exclusivity until it has a lock on the object that is returned by the expression. This prevents an expression from changing values during the running of several threads, which can give unexpected results from your code.

Note   The type of the expression in a SyncLock statement must be a reference type, such as a class, a module, an interface, array or delegate.
Example
Class Cache
   Private Shared Sub Add(ByVal x As Object)
      SyncLock GetType(Cache)
      End SyncLock
   End Sub

   Private Shared Sub Remove(ByVal x As Object)
      SyncLock GetType(Cache)
      End SyncLock
   End Sub
End Class
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值