PDA

View Full Version : کاربرد دستور SyncLock



mr_esmaily
جمعه 09 مرداد 1383, 11:37 صبح
سلام
اطلاعاتی در مورد کاربرد این دستور می خواستم.
باتشکر.

sh
یک شنبه 11 مرداد 1383, 17:00 عصر
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

sh
یک شنبه 11 مرداد 1383, 17:23 عصر
SyncLock. Allows an object to be locked. If another thread tries to lock that same object, it is blocked until the first thread releases. Use SyncLock carefully, because problems can result from the misuse of SyncLock