ReaderWriterLockSlim.IsWriteLockHeld 屬性

定義

取得值,表示目前執行緒是否已進入寫入模式的鎖定。Gets a value that indicates whether the current thread has entered the lock in write mode.

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

屬性值

如果目前執行緒已進入寫入模式,則為 true,否則為 falsetrue if the current thread has entered write mode; otherwise, false.

範例

下列範例顯示如何使用IsWriteLockHeld屬性, 以在目前線程意外進入寫入模式時產生判斷提示。The following example shows how to use the IsWriteLockHeld property to generate an assert if the current thread has entered write mode unexpectedly.

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))

備註

這個屬性適用于判斷提示, 或用於其他的偵錯工具。This property is intended for use in asserts or for other debugging purposes. 請勿使用它來控制程式執行的流程。Do not use it to control the flow of program execution.

適用於