Dispatcher.VerifyAccess 메서드

정의

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

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

예외

호출 스레드에서 이 Dispatcher에 액세스할 수 없는 경우

예제

다음 예제에서는 VerifyAccess 스레드가 스레드에 액세스할 수 있는지 여부를 결정 하는 Button 만들어진 합니다. 메서드는 개체를 인수로 사용합니다. 이 인수는 .로 캐스팅 Button됩니다. VerifyAccess 스레드에 대한 Dispatcher Button 액세스를 확인하기 위해 메서드가 호출됩니다.

호출 스레드에 대한 액세스 권한이 DispatcherButton 있는 경우 해당 스레드는 해당 Button멤버에 액세스하여 업데이트됩니다.

호출 스레드에서 액세스 되지 않은 경우는 InvalidOperationException throw 됩니다. 이 예제에서는 예외를 catch하고 인수 Dispatcher 로 수락 Button 하는 대리자를 해당 Button대리자로 푸시합니다. 이렇게 Dispatcher 하면 .를 업데이트하는 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수 있습니다.

이 메서드는 public입니다. 따라서 모든 스레드가 해당 스레드에 대한 액세스 권한이 Dispatcher있는지 확인할 수 있습니다.

호출 스레드에 CheckAccess 대한 액세스 권한이 없는 경우 부울과 예외를 throw하는 Dispatcher 경우의 차이 CheckAccess VerifyAccessVerifyAccess 부울을 반환합니다.

적용 대상

추가 정보