ControlCollection.SyncRoot 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤 컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.
public:
property System::Object ^ SyncRoot { System::Object ^ get(); };
public object SyncRoot { get; }
member this.SyncRoot : obj
Public ReadOnly Property SyncRoot As Object
속성 값
Object 컬렉션을 동기화하는 데 사용됩니다.
구현
예제
다음 코드 예제에서는 컨트롤myButton의 컬렉션을 통해 ControlCollection 열거 하는 메서드를 Button 만듭니다. 열거자를 만들 IsSynchronized 때 작업이 스레드로부터 안전한지 확인하기 위해 속성이 검사되고, 그렇지 않은 SyncRoot 경우 속성은 작업 스레드를 안전하게 만드는 개체를 가져오는 데 사용됩니다. 열거형이 완료되면 속성 값 IsReadOnly 이 포함된 페이지에서 컨트롤의 Label 속성으로 Text 기록됩니다.
// 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