ReaderWriterLockSlim.WaitingReadCount 屬性

定義

取得等待進入讀取模式鎖定狀態的執行緒總數。

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

屬性值

等待進入讀取模式的執行緒總數。

範例

下列範例示範如何使用 WaitingReadCount 屬性來產生事件記錄檔專案,如果封鎖的執行緒數目,等候進入讀取模式,超過臨界值。

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

備註

只針對偵錯、分析及記錄目的使用這個屬性,而不是控制演算法的行為。 結果可以在計算結果後立即變更。 因此,根據這個屬性做出決策並不安全。

適用於