Dispatcher.VerifyAccess 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
호출 스레드에 이 Dispatcher액세스 권한이 있는지 여부를 확인합니다.
public:
void VerifyAccess();
public void VerifyAccess();
member this.VerifyAccess : unit -> unit
Public Sub VerifyAccess ()
예외
호출 스레드는 이 Dispatcher에 액세스할 수 없습니다.
예제
다음 예제에서는 스레드가 만들어진 스레드 VerifyAccess 에 대한 액세스 권한이 있는지 여부를 확인하는 데 사용합니다Button. 메서드는 개체를 인수로 사용합니다. 이 인수는 .로 캐스팅 Button됩니다. VerifyAccess 스레드에 대한 DispatcherButton 액세스를 확인하기 위해 메서드가 호출됩니다.
호출 스레드에 대한 액세스 권한이 DispatcherButton 있는 경우 해당 스레드는 해당 멤버에 액세스하여 업데이트됩니다Button.
호출 스레드에 액세스 권한이 없으면 throw InvalidOperationException 됩니다. 이 예제에서는 예외를 catch하고 인수 Button 로 허용하는 Dispatcher 대리자를 해당 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(),
"Exception 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 대한 액세스 권한이 VerifyAccess 없으며 예외를 throw하는 경우의 차이 CheckAccessDispatcher 는 VerifyAccess 부울을 반환합니다.