ReaderWriterLockSlim.WaitingWriteCount 屬性

定義

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

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

屬性值

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

範例

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

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

備註

此屬性僅適用于偵錯工具、分析和記錄用途,而不是用來控制演算法的行為。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.

適用於