DispatcherObject.CheckAccess 메서드

정의

호출 스레드가 이 DispatcherObject에 액세스할 수 있는지 여부를 확인합니다.

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

반환

Boolean

호출 스레드에서 이 개체에 액세스할 수 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 CheckAccess 스레드가 스레드에 액세스할 수 있는지 여부를 결정 하는 Button 만들어진 합니다. 합니다 CheckAccess 메서드는 Button 스레드가 액세스할 수 있는지 확인 하기 위해 호출 됩니다. 호출 스레드가 액세스 하는 경우는 Button 방금의 멤버에 액세스 하 여 업데이트 됩니다는 Button고, 그렇지 않으면 허용 되는 대리자를를 Button 인수로 게시 되는 DispatcherButton.

// Uses the DispatcherObject.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.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
            // Pushing update method on the Dispatcher of the UI thread
            theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                new UpdateUIDelegate(UpdateButtonUI), theButton);
        }
    }
}
' Uses the DispatcherObject.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.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
            ' Pushing 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합니다.

스레드에 대 한이 있는지를 확인할 수 있습니다 DispatcherObject합니다.

간의 차이점 CheckAccess 하 고 VerifyAccessCheckAccess 호출 스레드에서이에 대 한 액세스에 있는지 여부를 지정 하는 부울 값을 반환 DispatcherObjectVerifyAccess 호출 스레드를 권한이 없는 경우 예외를 throw 합니다 이 DispatcherObject합니다.

이 메서드를 호출 하는 것은 호출과 동일 CheckAccess 연결 된 Dispatcher 개체입니다.

적용 대상