Share via


DTSReadOnlyCollectionBase.IsSynchronized Propriété

Définition

Obtient une valeur qui indique si l’accès à DTSReadOnlyCollectionBase 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é

true si l’accès DTSReadOnlyCollectionBase au fichier est synchronisé (thread-safe) ; sinon, false. La valeur par défaut est false.

Implémente

Exemples

Il ArrayList s’agit d’une classe .NET Framework qui hérite et implémente la IsSynchronized propriété. L’exemple de code suivant montre comment synchroniser un ArrayList, déterminer si un ArrayList est synchronisé et utiliser un synchronisé ArrayList.

using System;  
using System.Collections;  
public class SamplesArrayList    
{  
   public static void Main()    
   {  
      // Creates and initializes a new ArrayList.  
      ArrayList myAL = new ArrayList();  
      myAL.Add( "The" );  
      myAL.Add( "quick" );  
      myAL.Add( "brown" );  
      myAL.Add( "fox" );  

      // Creates a synchronized wrapper around the ArrayList.  
      ArrayList mySyncdAL = ArrayList.Synchronized( myAL );  

      // Displays the sychronization status of both ArrayLists.  
      Console.WriteLine( "myAL is {0}.", myAL.IsSynchronized ? "synchronized" : "not synchronized" );  
      Console.WriteLine( "mySyncdAL is {0}.", mySyncdAL.IsSynchronized ? "synchronized" : "not synchronized" );  
   }  
}  
Imports System  
Imports System.Collections  
Public Class SamplesArrayList  
   Public Shared  Sub Main()  
      ' Creates and initializes a new ArrayList.  
      Dim myAL As ArrayList =  New ArrayList()   
      myAL.Add("The")  
      myAL.Add("quick")  
      myAL.Add("brown")  
      myAL.Add("fox")  

      ' Creates a synchronized wrapper around the ArrayList.  
      Dim mySyncdAL As ArrayList =  ArrayList.Synchronized(myAL)   

      ' Displays the sychronization status of both ArrayLists.  
      Console.WriteLine("myAL is {0}.", myAL.IsSynchronized ? "synchronized" : "not synchronized")  
      Console.WriteLine("mySyncdAL is {0}.", mySyncdAL.IsSynchronized ? "synchronized" : "not synchronized")  
   End Sub  
End Class  

Exemple de sortie :

myAL n’est pas synchronisé.

mySyncdAL est synchronisé.

Remarques

Implémente ICollection.IsSynchronized. Si une collection est thread safe, la IsSynchronized propriété retourne true, et le programmeur n’a rien à faire pour conserver le thread de collection sécurisé.

Si la propriété retourne false, la propriété SyncRoot retourne un objet qui peut être utilisé avec le mot clé de verrou C#. Pour plus d’informations, consultez ICollection.IsSynchronized.

S’applique à