ControlCollection.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'oggetto ControlCollection è sincronizzato.
public:
property bool IsSynchronized { bool get(); };
public bool IsSynchronized { get; }
member this.IsSynchronized : bool
Public ReadOnly Property IsSynchronized As Boolean
Valore della proprietà
Questa proprietà è sempre false.
Implementazioni
Esempio
Nell'esempio di codice seguente viene creato un metodo che enumera l'insieme ControlCollection di un Button controllo , myButton. Quando viene creato l'enumeratore, la IsSynchronized proprietà viene controllata per verificare se l'operazione è thread-safe e, in caso contrario, viene utilizzata la SyncRoot proprietà per ottenere un oggetto per rendere thread-safe l'operazione. Al termine dell'enumerazione, il valore della IsReadOnly proprietà viene scritto come Text proprietà di un Label controllo nella pagina contenitore.
// 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)
{
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