Condividi tramite


ReaderWriterLockSlim.CurrentReadCount Proprietà

Definizione

Ottiene il numero totale di thread univoci che hanno immesso il blocco in modalità di lettura.

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

Valore della proprietà

Numero di thread univoci che hanno immesso il blocco in modalità di lettura.

Esempio

Nell'esempio seguente viene illustrato come utilizzare la CurrentReadCount proprietà per generare una voce del registro eventi se il numero di thread in modalità di lettura supera una soglia.

using (ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim()) {
Using rwLock As New ReaderWriterLockSlim()
if (!EventLog.SourceExists("MySource"))
{
    EventLog.CreateEventSource("MySource", "MyPerformanceLog");
}
EventLog performanceLog = new EventLog();
performanceLog.Source = "MySource";
If Not EventLog.SourceExists("MySource") Then
    EventLog.CreateEventSource("MySource", "MyPerformanceLog")
End If
Dim performanceLog As New EventLog()
performanceLog.Source = "MySource"
int readCt = rwLock.CurrentReadCount;
if (readCt > READ_THRESHOLD)
{
    performanceLog.WriteEntry(String.Format(
        "{0} reader threads; exceeds recommended maximum.", readCt));
}
Dim readCt As Integer = rwLock.CurrentReadCount
If readCt > READ_THRESHOLD Then
    performanceLog.WriteEntry(String.Format( _
        "{0} reader threads; exceeds recommended maximum.", readCt))
End If

Commenti

Un thread viene conteggiato una sola volta, anche se il blocco consente la ricorsione e il thread è entrato in modalità di lettura più volte.

Utilizzare questa proprietà solo per scopi di debug, profilatura e registrazione e non per controllare il comportamento di un algoritmo. I risultati possono cambiare non appena sono stati calcolati. Pertanto, non è sicuro prendere decisioni basate su questa proprietà.

Si applica a