共用方式為


VariablesCollection.IsSynchronized Property

Gets a value indicating whether access to the collection is synchronized (thread-safe).

命名空間: Microsoft.SqlServer.Dts.Tasks.Exec80PackageTask
組件: Microsoft.SqlServer.Exec80PackageTask (in microsoft.sqlserver.exec80packagetask.dll)

語法

'宣告
Public Overridable ReadOnly Property IsSynchronized As Boolean
public virtual bool IsSynchronized { get; }
public:
virtual property bool IsSynchronized {
    bool get ();
}
/** @property */
public boolean get_IsSynchronized ()
public function get IsSynchronized () : boolean

屬性值

true if access to the collection is synchronized (thread-safe); otherwise, false. The default is false.

備註

Implements ICollection.IsSynchronized. If a collection is thread safe, the IsSynchronized property returns true, and the programmer does not have to do anything to keep the collection thread safe.

If the property returns false, then the SyncRoot property returns an object that can be used with the C# lock keyword. For more information, see ICollection.IsSynchronized.

範例

The ArrayList is a .NET Framework Class that inherits and implements the IsSynchronized property. The following code example shows how to synchronize an ArrayList, determine if an ArrayList is synchronized and use a 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

Sample Output:

myAL is not synchronized.

mySyncdAL is synchronized.

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

平台

開發平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

目標平台

如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。

請參閱

參考

VariablesCollection Class
VariablesCollection Members
Microsoft.SqlServer.Dts.Tasks.Exec80PackageTask Namespace