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 a DTSReadOnlyCollectionBase è 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 a DTSReadOnlyCollectionBase è 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 oggetto ArrayList
, determinare se un oggetto ArrayList
è sincronizzato e utilizzare un oggetto Synchronized 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 true
e il programmatore non deve eseguire alcuna operazione per assicurare che la raccolta sia thread-safe.
Se la proprietà restituisce false
, la proprietà SyncRoot restituisce un oggetto che può essere utilizzato con la parola chiave lock di C#. Per ulteriori informazioni, vedere ICollection. IsSynchronized.