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 差異 VerifyAccess 是,會傳回 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.

適用於