Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Ruft einen Wert ab, der angibt, ob der Zugriff auf die SortedList synchronisiert (threadsicher) ist.
Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overridable ReadOnly Property IsSynchronized As Boolean
'Usage
Dim instance As SortedList
Dim value As Boolean
value = instance.IsSynchronized
public virtual bool IsSynchronized { get; }
public:
virtual property bool IsSynchronized {
bool get ();
}
/** @property */
public boolean get_IsSynchronized ()
public function get IsSynchronized () : boolean
Eigenschaftenwert
true, wenn der Zugriff auf die SortedList synchronisiert (threadsicher) ist, andernfalls false. Der Standardwert ist false.
Hinweise
Zur Gewährleistung der Threadsicherheit von SortedList müssen alle Operationen unter Verwendung des Wrappers ausgeführt werden, der von der Synchronized-Methode zurückgegeben wird.
Die Enumeration einer Auflistung ist systemintern keine threadsichere Prozedur. Selbst wenn eine Auflistung synchronisiert ist, besteht die Möglichkeit, dass andere Threads sie ändern. Dies führt dazu, dass der Enumerator eine Ausnahme auslöst. Sie können während der Enumeration Threadsicherheit gewährleisten, indem Sie entweder die Auflistung während der gesamten Enumeration sperren oder die Ausnahmen abfangen, die durch Änderungen ausgelöst werden, die von anderen Threads vorgenommen werden.
Beispiel
Das folgende Codebeispiel veranschaulicht, wie die Auflistung mithilfe von SyncRoot während der gesamten Enumeration gesperrt wird:
SortedList myCollection = new SortedList();
lock(myCollection.SyncRoot) {
foreach (Object item in myCollection) {
// Insert your code here.
}
}
Dim myCollection As New SortedList()
Dim item As Object
SyncLock myCollection.SyncRoot
For Each item In myCollection
' Insert your code here.
Next item
End SyncLock
Das Abrufen des Werts dieser Eigenschaft ist ein O(1)-Vorgang.
Im folgenden Beispiel wird gezeigt, wie Sie eine SortedList synchronisieren, eine synchronisierte SortedList verwenden und wie Sie ermitteln, ob eine SortedList synchronisiert ist.
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic
Public Class SamplesSortedList
Public Shared Sub Main()
' Creates and initializes a new SortedList.
Dim mySL As New SortedList()
mySL.Add(2, "two")
mySL.Add(3, "three")
mySL.Add(1, "one")
mySL.Add(0, "zero")
mySL.Add(4, "four")
' Creates a synchronized wrapper around the SortedList.
Dim mySyncdSL As SortedList = SortedList.Synchronized(mySL)
' Displays the sychronization status of both SortedLists.
Dim msg As String
If mySL.IsSynchronized Then
msg = "synchronized"
Else
msg = "not synchronized"
End If
Console.WriteLine("mySL is {0}.", msg)
If mySyncdSL.IsSynchronized Then
msg = "synchronized"
Else
msg = "not synchronized"
End If
Console.WriteLine("mySyncdSL is {0}.", msg)
End Sub
End Class
' This code produces the following output.
'
' mySL is not synchronized.
' mySyncdSL is synchronized.
using System;
using System.Collections;
public class SamplesSortedList {
public static void Main() {
// Creates and initializes a new SortedList.
SortedList mySL = new SortedList();
mySL.Add( 2, "two" );
mySL.Add( 3, "three" );
mySL.Add( 1, "one" );
mySL.Add( 0, "zero" );
mySL.Add( 4, "four" );
// Creates a synchronized wrapper around the SortedList.
SortedList mySyncdSL = SortedList.Synchronized( mySL );
// Displays the sychronization status of both SortedLists.
Console.WriteLine( "mySL is {0}.", mySL.IsSynchronized ? "synchronized" : "not synchronized" );
Console.WriteLine( "mySyncdSL is {0}.", mySyncdSL.IsSynchronized ? "synchronized" : "not synchronized" );
}
}
/*
This code produces the following output.
mySL is not synchronized.
mySyncdSL is synchronized.
*/
#using <system.dll>
using namespace System;
using namespace System::Collections;
int main()
{
// Creates and initializes a new SortedList.
SortedList^ mySL = gcnew SortedList;
mySL->Add( 2, "two" );
mySL->Add( 3, "three" );
mySL->Add( 1, "one" );
mySL->Add( (int^)0, "zero" );
mySL->Add( 4, "four" );
// Creates a synchronized wrapper around the SortedList.
SortedList^ mySyncdSL = SortedList::Synchronized( mySL );
// Displays the sychronization status of both SortedLists.
Console::WriteLine( "mySL is {0}.", mySL->IsSynchronized ? (String^)"synchronized" : "not synchronized" );
Console::WriteLine( "mySyncdSL is {0}.", mySyncdSL->IsSynchronized ? (String^)"synchronized" : "not synchronized" );
}
/*
This code produces the following output.
mySL is not synchronized.
mySyncdSL is synchronized.
*/
import System.*;
import System.Collections.*;
public class SamplesSortedList
{
public static void main(String[] args)
{
// Creates and initializes a new SortedList.
SortedList mySL = new SortedList();
mySL.Add((Int32)2, "two");
mySL.Add((Int32)3, "three");
mySL.Add((Int32)1, "one");
mySL.Add((Int32)0, "zero");
mySL.Add((Int32)4, "four");
// Creates a synchronized wrapper around the SortedList.
SortedList mySyncdSL = SortedList.Synchronized(mySL);
// Displays the sychronization status of both SortedLists.
Console.WriteLine("mySL is {0}.", (mySL.get_IsSynchronized()) ?
"synchronized" : "not synchronized");
Console.WriteLine("mySyncdSL is {0}.",
(mySyncdSL.get_IsSynchronized()) ?
"synchronized" : "not synchronized");
} //main
} //SamplesSortedList
/*
This code produces the following output.
mySL is not synchronized.
mySyncdSL is synchronized.
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0
Siehe auch
Referenz
SortedList-Klasse
SortedList-Member
System.Collections-Namespace
SyncRoot
Synchronized