Partager via


StringDictionary.IsSynchronized Propriété

Définition

Obtient une valeur indiquant si l’accès à l’objet StringDictionary est synchronisé (thread safe).

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

Valeur de propriété

true si l’accès StringDictionary au thread est synchronisé (thread safe) ; sinon, false.

Exemples

L’exemple de code suivant montre comment verrouiller la collection à l’aide de l’énumération SyncRoot entière.

StringDictionary myCollection = new StringDictionary();
lock(myCollection.SyncRoot)
{
    foreach (Object item in myCollection)
    {
        // Insert your code here.
    }
}
Dim myCollection As New StringDictionary()
SyncLock myCollection.SyncRoot
    For Each item As Object In myCollection
        ' Insert your code here.
    Next item
End SyncLock

La récupération de la valeur de cette propriété est une opération O(1).

Remarques

Une StringDictionary instance n’est pas synchronisée. Les classes dérivées peuvent fournir une version synchronisée de la propriété à l’aide StringDictionary de la SyncRoot propriété.

L’énumération par le biais d’une collection n’est intrinsèquement pas une procédure thread-safe. Même lorsqu’une collection est synchronisée, d’autres threads peuvent toujours modifier la collection, ce qui provoque la levée d’une exception par l’énumérateur. Pour garantir la sécurité des threads pendant l’énumération, vous pouvez verrouiller la collection pendant toute l’énumération ou intercepter les exceptions résultant des modifications apportées par d’autres threads.

S’applique à