DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess Method

定义

强制执行调用线程可以访问此DispatcherObjectEnforces that the calling thread has access to this DispatcherObject.

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

异常

调用线程不具有访问此DispatcherObjectthe calling thread does not have access to this DispatcherObject.

示例

下面的示例使用VerifyAccess来确定线程是否具有访问该线程的Button上创建。The following example uses VerifyAccess to determine whether a thread has access to the thread that a Button was created on. 如果调用线程不具有访问权限,InvalidOperationException引发。If the calling thread does not have access, an InvalidOperationException is thrown.

// Check if this thread has access to this object.
theButton.VerifyAccess();

// Thread has access to the object, so update the UI.
UpdateButtonUI(theButton);
' Check if this thread has access to this object.
theButton.VerifyAccess()

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

注解

只有线程Dispatcher创建在可访问DispatcherObjectOnly the thread the Dispatcher was created on may access the DispatcherObject.

任何线程可以检查以查看其是否具有访问此DispatcherObjectAny thread can check to see whether it has access to this DispatcherObject.

之间的差异CheckAccessVerifyAccess在于CheckAccess返回一个布尔值,指定调用线程是否具有访问此DispatcherObjectVerifyAccess将引发异常,如果调用线程不具有访问这DispatcherObjectThe difference between CheckAccess and VerifyAccess is that CheckAccess returns a Boolean that specifies whether the calling thread has access to this DispatcherObject and VerifyAccess throws an exception if the calling thread does not have access to the this DispatcherObject.

适用于