Dispatcher.CheckAccess Dispatcher.CheckAccess Dispatcher.CheckAccess Dispatcher.CheckAccess Method

정의

호출 스레드가 이 Dispatcher에 연결된 스레드인지 여부를 확인합니다.Determines whether the calling thread is the thread associated with this Dispatcher.

public:
 bool CheckAccess();
public bool CheckAccess ();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean

반환

호출 스레드가 이 Dispatcher에 연결된 스레드이면 true이고, 그렇지 않으면 false입니다.true if the calling thread is the thread associated with this Dispatcher; otherwise, false.

예제

다음 예제에서는 CheckAccess 스레드가에 대 한 액세스에 있는지 확인 하는 Button합니다.The following example uses CheckAccess to determine whether a thread has access to a Button. CheckAccess 메서드를 Dispatcher 연관는 Button 스레드가 액세스할 수 있는지 확인 하기 위해 호출 됩니다.The CheckAccess method on the Dispatcher associated with the Button is called to verify access to the thread. 호출 스레드를 액세스할 수 있는 경우는 Dispatcher, Button 의 멤버에 액세스 하 여 업데이트 됩니다는 Button이 고, 그렇지 않으면 허용 되는 대리자를를 Button 인수로 배치를 Dispatcher합니다.If the calling thread has access to the Dispatcher, the Button is updated by accessing the members of the Button; otherwise, a delegate, which accepts a Button as an argument, is placed onto the Dispatcher. 합니다 Dispatcher 업데이트 작업을 위임 하는 Button합니다.The Dispatcher will delegate the work of updating the Button.

// Uses the Dispatcher.CheckAccess method to determine if 
// the calling thread has access to the thread the UI object is on.
private void TryToUpdateButtonCheckAccess(object uiObject)
{
    Button theButton = uiObject as Button;

    if (theButton != null)
    {
        // Checking if this thread has access to the object.
        if (theButton.Dispatcher.CheckAccess())
        {
            // This thread has access so it can update the UI thread.
            UpdateButtonUI(theButton);
        }
        else
        {
            // This thread does not have access to the UI thread.
            // Place the update method on the Dispatcher of the UI thread.
            theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                new UpdateUIDelegate(UpdateButtonUI), theButton);
        }
    }
}
' Uses the Dispatcher.CheckAccess method to determine if 
' the calling thread has access to the thread the UI object is on.
Private Sub TryToUpdateButtonCheckAccess(ByVal uiObject As Object)
	Dim theButton As Button = TryCast(uiObject, Button)

	If theButton IsNot Nothing Then
		' Checking if this thread has access to the object.
		If theButton.Dispatcher.CheckAccess() Then
			' This thread has access so it can update the UI thread.
			UpdateButtonUI(theButton)
		Else
			' This thread does not have access to the UI thread.
			' Place the update method on the Dispatcher of the UI thread.
			theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New UpdateUIDelegate(AddressOf UpdateButtonUI), theButton)
		End If
	End If
End Sub

설명

DispatcherDispatcherObject 만들어집니다 개체에 액세스할 수 있습니다.Only the Dispatcher that a DispatcherObject is created on may access the object. 사용 하 여 Invoke 또는 BeginInvoke 다른 스레드에서 개체를 액세스할 수 있습니다.Use Invoke or BeginInvoke to access the object from a different thread.

CheckAccess 모든 스레드에서 호출할 수 있습니다.CheckAccess can be called from any thread.

간의 차이 CheckAccessVerifyAccess 됩니다 CheckAccess 호출 스레드에 있는지에 대 한 액세스를 나타내는 부울 값을 반환 합니다 DispatcherVerifyAccess 예외를 throw 합니다.The difference between CheckAccess and VerifyAccess is CheckAccess returns a Boolean indicating whether the calling thread has access to the Dispatcher and VerifyAccess throws an exception.

적용 대상

추가 정보