ReaderWriterLockSlim.WaitingUpgradeCount 属性

定义

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

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

属性值

Int32

等待进入可升级模式的线程总数。

示例

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

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

注解

仅对调试、分析和日志记录目的使用此属性,而不是控制算法的行为。 一旦计算结果,结果就会发生更改。 因此,基于此属性做出决策是不安全的。

适用于