ForEachItems.IsSynchronized Proprietà

Definizione

Restituisce un valore booleano che indica se l'accesso ForEachItems alla raccolta è sincronizzato (thread-safe).

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

Valore della proprietà

true se l'accesso alla raccolta è sincronizzato (thread-safe); in caso contrario, false. Il valore predefinito è false.

Implementazioni

Esempio

È ArrayList una classe .NET Framework che eredita e implementa la IsSynchronized proprietà. Nell'esempio di codice seguente viene illustrato come sincronizzare un ArrayListoggetto , determinare se un ArrayList oggetto è sincronizzato e usare un oggetto sincronizzato 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  

Esempio di output

myAL non è sincronizzato.

mySyncdAL è sincronizzato.

Commenti

Implementa ICollection.IsSynchronized. Se una raccolta è thread safe, la IsSynchronized proprietà restituisce truee il programmatore non deve eseguire alcuna operazione per mantenere sicuro il thread di raccolta.

Se la proprietà restituisce false, la proprietà SyncRoot restituisce un oggetto che può essere usato con la parola chiave di blocco C#. Per altre informazioni, vedere ICollection.IsSynchronized.

Si applica a