BitArray.IsSynchronized Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une valeur indiquant si l’accès à l’objet BitArray est synchronisé (thread safe).
public:
property bool IsSynchronized { bool get(); };
public bool IsSynchronized { get; }
member this.IsSynchronized : bool
Public ReadOnly Property IsSynchronized As Boolean
Valeur de propriété
Cette propriété est toujours false.
Implémente
Exemples
L’exemple de code suivant montre comment verrouiller la collection à l’aide de l’énumération SyncRoot entière.
BitArray myCollection = new BitArray(64, true);
lock(myCollection.SyncRoot)
{
foreach (object item in myCollection)
{
// Insert your code here.
}
}
Dim myCollection As New BitArray(64, true)
SyncLock myCollection.SyncRoot
For Each item In myCollection
' Insert your code here.
Next item
End SyncLock
Cette méthode est une O(1) opération.
Remarques
BitArray implémente la IsSynchronized propriété, car elle est requise par l’interface System.Collections.ICollection .
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.