ReaderWriterLockSlim.WaitingWriteCount 属性

定义

获取等待进入写入模式锁定状态的线程总数。

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

属性值

等待进入写入模式的线程总数。

示例

以下示例演示如何使用 WaitingWriteCount 属性生成事件日志条目,如果阻塞的线程数(等待进入写入模式)超过阈值。

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

注解

此属性仅用于调试、分析和日志记录目的,而不用于控制算法的行为。 计算结果后,结果可能会立即更改。 因此,基于此属性做出决策是不安全的。

适用于