ReaderWriterLockSlim.IsReadLockHeld 属性

定义

获取一个值,该值指示当前线程是否已进入读取模式的锁定状态。

public:
 property bool IsReadLockHeld { bool get(); };
public bool IsReadLockHeld { get; }
member this.IsReadLockHeld : bool
Public ReadOnly Property IsReadLockHeld As Boolean

属性值

Boolean

如果当前线程已进入读取模式,则为 true;否则为 false

示例

以下示例演示如何使用 IsReadLockHeld 属性在当前线程意外进入读取模式时生成断言。

using (ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim()) {
Using rwLock As New ReaderWriterLockSlim()
Debug.Assert(!rwLock.IsReadLockHeld,
    String.Format("Thread {0} already held the read lock when MyFunction began executing.",
                  Thread.CurrentThread.ManagedThreadId));
Debug.Assert(Not rwLock.IsReadLockHeld, _
    String.Format("Thread {0} already held the read lock when MyFunction began executing.", _
                  Thread.CurrentThread.ManagedThreadId))

注解

此属性用于断言或其他调试目的。 不要使用它来控制程序执行流。

适用于