Dispatcher.VerifyAccess 메서드

정의

호출 스레드가 이 Dispatcher에 액세스할 수 있는지 여부를 확인합니다.Determines whether the calling thread has access to this Dispatcher.

public:
 void VerifyAccess();
public void VerifyAccess ();
member this.VerifyAccess : unit -> unit
Public Sub VerifyAccess ()

예외

호출 스레드에서 이 Dispatcher에 액세스할 수 없는 경우The calling thread does not have access to this Dispatcher.

예제

다음 예제에서는 VerifyAccess 스레드가 스레드에 액세스할 수 있는지 여부를 결정 하는 Button 만들어진 합니다.The following example uses VerifyAccess to determine whether a thread has access to the thread that a Button was created on. 로 캐스팅 되는 인수로 서 개체를 사용 하는 메서드를 Button입니다.The method takes an object as an argument, which is cast to a Button. VerifyAccess 메서드를 DispatcherButton 스레드가 액세스할 수 있는지 확인 하기 위해 호출 됩니다.The VerifyAccess method on the Dispatcher of the Button is called to verify access to the thread.

호출 스레드를 액세스할 수 있는 경우는 Dispatcher, Button 만의 멤버에 액세스 하 여 업데이트 되는 Button합니다.If the calling thread has access to the Dispatcher, the Button is updated by just accessing the members of the Button.

호출 스레드에서 액세스 되지 않은 경우는 InvalidOperationException throw 됩니다.If the calling thread does not have access, an InvalidOperationException is thrown. 이 예제에서는 예외를 catch 하 고 허용 되는 대리자를 푸시를 Button 인수로는 DispatcherButton합니다.This example catches the exception and pushes a delegate, which accepts a Button as an argument, onto the Dispatcher of the Button. Dispatcher 는 업데이트 작업 수행을 Button입니다.This Dispatcher will do the work of updating the Button.

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

    if (theButton != null)
    {
        try
        {   
            // Check if this thread has access to this object.
            theButton.Dispatcher.VerifyAccess();

            // The thread has access to the object, so update the UI.
            UpdateButtonUI(theButton);
        }

        // Cannot access objects on the thread.
        catch (InvalidOperationException e)
        {
            // Exception Error Message.
            MessageBox.Show("Exception ToString: \n\n" + e.ToString(), 
                "Execption Caught! Thrown During AccessVerify().");

            MessageBox.Show("Pushing job onto UI Thread Dispatcher");

            // Placing job onto the Dispatcher of the UI Thread.
            theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                new UpdateUIDelegate(UpdateButtonUI), theButton);
        }
    }
}
' Uses the Dispatcher.VerifyAccess method to determine if 
' the calling thread has access to the thread the UI object is on.
Private Sub TryToUpdateButtonVerifyAccess(ByVal uiObject As Object)
    Dim theButton As Button = TryCast(uiObject, Button)

    If theButton IsNot Nothing Then
        Try
            ' Check if this thread has access to this object.
            theButton.Dispatcher.VerifyAccess()

            ' The thread has access to the object, so update the UI.
            UpdateButtonUI(theButton)

            ' Cannot access objects on the thread.
        Catch e As InvalidOperationException
            ' Exception Error Message.
            MessageBox.Show("Exception ToString: " & vbLf & vbLf & e.ToString(), "Execption Caught! Thrown During AccessVerify().")

            MessageBox.Show("Pushing job onto UI Thread Dispatcher")

            ' Placing job onto the Dispatcher of the UI Thread.
            theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New UpdateUIDelegate(AddressOf UpdateButtonUI), theButton)
        End Try
    End If
End Sub

설명

스레드만 합니다 Dispatcher 만들어집니다에 액세스할 수는 Dispatcher합니다.Only the thread the Dispatcher is created on may access the Dispatcher.

이 메서드는 공용입니다. 따라서 모든 스레드 수 확인 권한을 있는지 확인 합니다 Dispatcher합니다.This method is public; therefore, any thread can check to see whether it has access to the Dispatcher.

간의 차이 CheckAccessVerifyAccess 됩니다 CheckAccess 호출 스레드를 권한이 없는 경우 부울 값을 반환 합니다 DispatcherVerifyAccess 예외를 throw 합니다.The difference between CheckAccess and VerifyAccess is CheckAccess returns a Boolean if the calling thread does not have access to the Dispatcher and VerifyAccess throws an exception.

적용 대상

추가 정보