DTSReadOnlyCollectionBase.IsSynchronized Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene un valore che indica se l'accesso DTSReadOnlyCollectionBase a è 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à
Vero se l'accesso al DTSReadOnlyCollectionBase Thread è sincronizzato; altrimenti falso. Il valore predefinito è false.
Implementazioni
Esempio
La ArrayList è una classe framework .NET che eredita e implementa la IsSynchronized proprietà. Nell'esempio di codice seguente viene illustrato come sincronizzare un oggetto ArrayList, determinare se un oggetto ArrayList è 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
Output di esempio:
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 il thread-safe della raccolta.
Se la proprietà restituisce false, allora la proprietà SyncRoot restituisce un oggetto che può essere usato con la parola chiave C# lock. Per ulteriori informazioni, vedi ICollection.IsSynchronized.