Dispatcher.CheckAccess 메서드

정의

호출 스레드가 이 Dispatcher에 연결된 스레드인지 여부를 확인합니다.

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

반환

Boolean

호출 스레드가 이 Dispatcher에 연결된 스레드이면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 스레드에 대한 액세스 권한이 있는지 여부를 확인하는 데 Button사용합니다CheckAccess. CheckAccess 스레드에 대한 Dispatcher 액세스를 확인하기 위해 연결된 Button 메서드가 호출됩니다. 호출 스레드에 대한 액세스 권한이 DispatcherButton 있는 경우 해당 스레드는 멤버Button에 액세스하여 업데이트됩니다. 그렇지 않으면 인수로 수락 Button 하는 대리자가 에 Dispatcher배치됩니다. 은 Dispatcher (을) 업데이트하는 작업을 위임합니다 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

설명

Dispatcher 생성된 개체 DispatcherObject 만 개체에 액세스할 수 있습니다. 다른 스레드에서 개체를 사용 Invoke 하거나 BeginInvoke 액세스합니다.

CheckAccess 는 모든 스레드에서 호출할 수 있습니다.

사이의 CheckAccess VerifyAccess 차이는 CheckAccess 호출 스레드가 해당 스레드에 대한 액세스 권한이 Dispatcher VerifyAccess 있고 예외를 throw하는지 여부를 나타내는 부울 값을 반환합니다.

적용 대상

추가 정보