SortedDictionary<TKey,TValue>.ValueCollection.ICollection.SyncRoot Propriedade

Definição

Obtém um objeto que pode ser usado para sincronizar o acesso ao ICollection.Gets an object that can be used to synchronize access to the ICollection.

property System::Object ^ System::Collections::ICollection::SyncRoot { System::Object ^ get(); };
object System.Collections.ICollection.SyncRoot { get; }
member this.System.Collections.ICollection.SyncRoot : obj
 ReadOnly Property SyncRoot As Object Implements ICollection.SyncRoot

Valor da propriedade

Object

Um objeto que pode ser usado para sincronizar o acesso à ICollection.An object that can be used to synchronize access to the ICollection. Na implementação padrão da SortedDictionary<TKey,TValue>.ValueCollection, essa propriedade sempre retorna a instância atual.In the default implementation of SortedDictionary<TKey,TValue>.ValueCollection, this property always returns the current instance.

Implementações

Comentários

As implementações padrão de coleções no namespace System.Collections.Generic não são sincronizadas.Default implementations of collections in the System.Collections.Generic namespace are not synchronized.

A enumeração por meio de uma coleção não é um procedimento thread-safe intrínseco.Enumerating through a collection is intrinsically not a thread-safe procedure. Para garantir acesso thread-safe durante a enumeração, é possível bloquear a coleção durante toda a enumeração.To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. Para permitir que a coleção seja acessada por vários threads para leitura e gravação, você deve implementar sua própria sincronização.To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

A SyncRoot propriedade retorna um objeto que pode ser usado para sincronizar o acesso ao ICollection .The SyncRoot property returns an object that can be used to synchronize access to the ICollection. A sincronização entrará em vigor somente se todos os threads bloquearem o objeto antes de acessar a coleção.Synchronization is effective only if all threads lock the object before accessing the collection. O código a seguir mostra o uso da SyncRoot propriedade para C#, C++ e Visual Basic.The following code shows the use of the SyncRoot property for C#, C++, and Visual Basic.

ICollection ic = ...;  
lock (ic.SyncRoot)   
{  
    // Access the collection.  
}  
Dim ic As ICollection = ...  
SyncLock ic.SyncRoot  
    ' Access the collection.  
End SyncLock  
ICollection^ ic = ...;  
try   
{  
    Monitor::Enter(ic->SyncRoot);  
    // Access the collection.  
}  
finally   
{  
    Monitor::Exit(ic->SyncRoot);  
}  

A obtenção do valor dessa propriedade é uma operação O(1).Getting the value of this property is an O(1) operation.

Aplica-se a

Confira também