HybridDictionary.IsSynchronized Proprietà

Definizione

Ottiene un valore che indica se la classe HybridDictionary è sincronizzata (thread-safe).

public:
 property bool IsSynchronized { bool get(); };
public bool IsSynchronized { get; }
member this.IsSynchronized : bool
Public ReadOnly Property IsSynchronized As Boolean

Valore della proprietà

Questa proprietà restituisce sempre false.

Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato come bloccare la raccolta usando durante SyncRoot l'intera enumerazione .

HybridDictionary^ myCollection = gcnew HybridDictionary();
bool lockTaken = false;
try
{
    Monitor::Enter(myCollection->SyncRoot, lockTaken);
    for each (Object^ item in myCollection)
    {
        // Insert your code here.
    }
}
finally
{
    if (lockTaken)
    {
        Monitor::Exit(myCollection->SyncRoot);
    }
}
HybridDictionary myCollection = new HybridDictionary();
lock(myCollection.SyncRoot)
{
    foreach (object item in myCollection)
    {
        // Insert your code here.
    }
}
Dim myCollection As New HybridDictionary()
SyncLock myCollection.SyncRoot
    For Each item In myCollection
        ' Insert your code here.
    Next
End SyncLock

Il recupero del valore di questa proprietà è un'operazione O(1).

Commenti

HybridDictionary implementa la IsSynchronized proprietà perché è richiesta dall'interfaccia System.Collections.ICollection .

Le classi derivate possono fornire una versione sincronizzata di HybridDictionary utilizzando la SyncRoot proprietà .

L'enumerazione di una raccolta non è di per sé una procedura thread-safe. Anche se una raccolta è sincronizzata, è possibile che venga modificata da altri thread, con conseguente generazione di un'eccezione da parte dell'enumeratore. Per garantire la protezione dei thread durante l'enumerazione, è possibile bloccare la raccolta per l'intera enumerazione oppure intercettare le eccezioni determinate dalle modifiche apportate da altri thread.

Si applica a

Vedi anche