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

定义

强制调用线程具有此 DispatcherObject 的访问权限。Enforces 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来确定线程是否有权访问在上创建的线程ButtonThe 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的线程可以DispatcherObject访问。Only the thread the Dispatcher was created on may access the DispatcherObject.

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

CheckAccess CheckAccess DispatcherObject之间的区别在于, 返回一个布尔值, 该值指定调用线程是否有权访问此VerifyAccess值, 如果调用线程不具有访问权限, 则会引发异常。 VerifyAccessDispatcherObjectThe 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.

适用于