TreeNodeCollection.SyncRoot Propriedade
Definição
Obtém um objeto que pode ser usado para sincronizar o acesso ao objeto TreeNodeCollection.Gets an object that can be used to synchronize access to the TreeNodeCollection object.
public:
property System::Object ^ SyncRoot { System::Object ^ get(); };
public object SyncRoot { get; }
member this.SyncRoot : obj
Public ReadOnly Property SyncRoot As Object
Valor da propriedade
Um Object que pode ser usado para sincronizar o acesso ao TreeNodeCollection .A Object that can be used to synchronize access to the TreeNodeCollection.
Implementações
Comentários
A SyncRoot propriedade fornece uma versão sincronizada do TreeNodeCollection que pode ser usada com o código de sincronização (Threading).The SyncRoot property provides a synchronized version of the TreeNodeCollection that can be used with synchronizing (threading) code.
Cuidado
A IsSynchronized propriedade dessa classe sempre retorna false , que indica que a TreeNodeCollection classe não está sincronizada (não thread-safe).The IsSynchronized property of this class always returns false, which indicates that the TreeNodeCollection class is not synchronized (not thread safe).
O código de sincronização deve executar operações no SyncRoot objeto do TreeNodeCollection , não diretamente por TreeNodeCollection si só.Synchronizing code must perform operations on the SyncRoot object of the TreeNodeCollection, not directly on the TreeNodeCollection itself. Isso garante a operação apropriada das coleções que são derivadas de outros objetos.This ensures proper operation of collections that are derived from other objects. Especificamente, ele mantém a sincronização adequada com outros threads que podem estar modificando o TreeNodeCollection objeto simultaneamente.Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the TreeNodeCollection object.
Observação
O objeto retornado nessa implementação é o System.Collections.ArrayList objeto usado para armazenar os TreeNode objetos na coleção.The object returned in this implementation is the System.Collections.ArrayList object used to store the TreeNode objects in the collection.
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. Mesmo quando uma coleção é sincronizada, outros threads ainda podiam modificar a coleção, o que faz com que o enumerador lance uma exceção.Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. Para garantir thread-safe durante a enumeração, é possível bloquear a coleção durante toda a enumeração ou verificar as exceções resultantes das alterações feitas por outros threads.To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
Para obter mais informações sobre a SyncRoot propriedade, consulte a ICollection.SyncRoot propriedade da System.Collections.ICollection interface.For more information on the SyncRoot property, see the ICollection.SyncRoot property of the System.Collections.ICollection interface.