ReaderWriterLockSlim.WaitingReadCount Property

Definition

取得等待進入讀取模式鎖定狀態的執行緒總數。Gets the total number of threads that are waiting to enter the lock in read mode.

public:
 property int WaitingReadCount { int get(); };
public int WaitingReadCount { get; }
member this.WaitingReadCount : int
Public ReadOnly Property WaitingReadCount As Integer

Property Value

Int32

等待進入讀取模式的執行緒總數。The total number of threads that are waiting to enter read mode.

Examples

下列範例顯示如何使用 WaitingReadCount 屬性來產生事件記錄檔專案,如果封鎖的執行緒數目(等待進入讀取模式)超過閾值。The following example shows how to use the WaitingReadCount property to generate an event log entry if the number of threads that are blocked, waiting to enter read mode, exceeds a threshold.

using (ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim()) {
Using rwLock As New ReaderWriterLockSlim()
int waitingReadCt = rwLock.WaitingReadCount;
if (waitingReadCt > READ_THRESHOLD)
{
    performanceLog.WriteEntry(String.Format(
        "{0} blocked reader threads; exceeds recommended maximum.", 
        waitingReadCt));
}
Dim waitingReadCt As Integer = rwLock.WaitingReadCount
If waitingReadCt > READ_THRESHOLD Then
    performanceLog.WriteEntry(String.Format( _
        "{0} blocked reader threads; exceeds recommended maximum.", _
        waitingReadCt))
End If

Remarks

此屬性僅適用于偵錯工具、分析和記錄用途,而不是用來控制演算法的行為。Use this property only for debugging, profiling, and logging purposes, and not to control the behavior of an algorithm. 結果會在計算後立即變更。The results can change as soon as they have been calculated. 因此,根據此屬性做出決策並不安全。Therefore, it is not safe to make decisions based on this property.

Applies to