DispatcherObject.VerifyAccess Method

Definition

强制调用线程具有此 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 ()

Exceptions

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

Examples

下面的示例使用 VerifyAccess 来确定线程是否有权访问在其上创建了 Button 的线程。The following example uses VerifyAccess to determine whether a thread has access to the thread that a Button was created on. 如果调用线程没有访问权限,则会引发 InvalidOperationExceptionIf 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)

Remarks

仅创建 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 将返回一个布尔值,该值指定调用线程是否有权访问此 DispatcherObject,如果调用线程无权访问此 VerifyAccess,则会引发异常。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.

Applies to