ReaderWriterLockSlim.IsWriteLockHeld 属性

定义

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

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

属性值

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

示例

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

using (ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim()) {
Using rwLock As New ReaderWriterLockSlim()
Debug.Assert(!rwLock.IsWriteLockHeld, 
    String.Format("Thread {0} is still holding the write lock after MyFunction has finished.", 
                  Thread.CurrentThread.ManagedThreadId));
Debug.Assert(Not rwLock.IsWriteLockHeld, _
    String.Format("Thread {0} is still holding the write lock after MyFunction has finished.", _
                  Thread.CurrentThread.ManagedThreadId))

注解

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

适用于