ControlCollection.SyncRoot Özellik

Tanım

Denetim koleksiyonuna erişimi eşitlemek için kullanılabilecek bir nesne alır.

public:
 property System::Object ^ SyncRoot { System::Object ^ get(); };
public object SyncRoot { get; }
member this.SyncRoot : obj
Public ReadOnly Property SyncRoot As Object

Özellik Değeri

Object

koleksiyonu Object eşitlemek için kullanılır.

Uygulamalar

Örnekler

Aşağıdaki kod örneği, myButtonbir denetim koleksiyonu aracılığıyla ControlCollection numaralandıran bir Button yöntem oluşturur. Numaralandırıcı oluşturulduğunda, IsSynchronized işlemin iş parçacığı güvenli olup olmadığını görmek için özellik denetlenirken, değilse, SyncRoot işlem iş parçacığını güvenli hale getirmek için bir nesne elde etmek için özelliği kullanılır. Numaralandırma tamamlandığında, özelliğin IsReadOnly değeri, içeren sayfadaki bir Label denetimin özelliği olarak Text yazılır.

// Create a method that enuberates through a 
// button//s ControlCollection in a thread-safe manner.  
public void ListControlCollection(object sender, EventArgs e)
{
   IEnumerator myEnumerator = myButton.Controls.GetEnumerator();

   // Check the IsSynchronized property. If False,
   // use the SyncRoot method to get an object that 
   // allows the enumeration of all controls to be 
   // thread safe.
   if (myButton.Controls.IsSynchronized == false)
   {
       lock (myButton.Controls.SyncRoot)
       {
           while (myEnumerator.MoveNext())
           {

               Object myObject = myEnumerator.Current;

               LiteralControl childControl = (LiteralControl)myEnumerator.Current;
               Response.Write("<b><br /> This is the  text of the child Control  </b>: " +
                              childControl.Text);
           }
           msgReadOnly.Text = myButton.Controls.IsReadOnly.ToString();
       }
   }       
}
' Create a method that enuberates through a 
' button's ControlCollection in a thread-safe manner.  
Public Sub ListControlCollection(sender As Object, e As EventArgs)
   Dim myEnumerator As IEnumerator = myButton.Controls.GetEnumerator()

   ' Check the IsSynchronized property. If False,
   ' use the SyncRoot method to get an object that 
   ' allows the enumeration of all controls to be 
   ' thread safe.
   If myButton.Controls.IsSynchronized = False Then
     SyncLock myButton.Controls.SyncRoot
       While (myEnumerator.MoveNext())

       Dim myObject As Object  = myEnumerator.Current
           
         Dim childControl As LiteralControl = CType(myEnumerator.Current, LiteralControl)
         Response.Write("<b><br /> This is the  text of the child Control  </b>: " & _
                        childControl.Text)
       End While
      msgReadOnly.Text = myButton.Controls.IsReadOnly.ToString()
      
      End SyncLock
   End If       
 End Sub

Şunlara uygulanır

Ayrıca bkz.