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.

適用於