DispatcherObject.VerifyAccess 方法

定义

强制调用线程具有此 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 来确定线程是否有权访问 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.

与之间的区别在于 CheckAccess VerifyAccessCheckAccess 返回一个布尔值,该值指定调用线程是否有权访问此值 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.

适用于