本文整理汇总了VB.NET中System.Threading.LockRecursionException类的典型用法代码示例。如果您正苦于以下问题:VB.NET LockRecursionException类的具体用法?VB.NET LockRecursionException怎么用?VB.NET LockRecursionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LockRecursionException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Threading
Class Example
' By default, the lock recursion policy for a new
' ReaderWriterLockSlim does not allow recursion.
Private Shared rwls As New ReaderWriterLockSlim()
Shared Sub ThreadProc()
Console.WriteLine("Acquire the reader lock.")
rwls.EnterReadLock()
Try
Console.WriteLine(vbCrLf & _
"Attempt to acquire the reader lock recursively:")
rwls.EnterReadLock()
Catch lre As LockRecursionException
Console.WriteLine("{0}: {1}", _
lre.GetType().Name, lre.Message)
End Try
Try
Console.WriteLine(vbCrLf & _
"Attempt to acquire the writer lock recursively:")
rwls.EnterWriteLock()
Catch lre As LockRecursionException
Console.WriteLine("{0}: {1}", _
lre.GetType().Name, lre.Message)
End Try
End Sub
Shared Sub Main()
Dim t As New Thread(AddressOf ThreadProc)
t.Start()
t.Join()
End Sub
End Class
输出:
Acquire the reader lock. Attempt to acquire the reader lock recursively: LockRecursionException: Recursive read lock acquisitions not allowed in this mode. Attempt to acquire the writer lock recursively: LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Consider using the upgrade lock.