DispatcherObject.VerifyAccess 方法

定義

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。

public:
 void VerifyAccess();
public void VerifyAccess ();
member this.VerifyAccess : unit -> unit
Public Sub VerifyAccess ()

例外狀況

呼叫執行緒無法存取這個 DispatcherObject

範例

下列範例會使用 VerifyAccess 來判斷線程是否能夠存取建立所在的執行緒 Button 。 如果呼叫執行緒沒有存取權, InvalidOperationException 則會擲回 。

// 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

任何執行緒都可以檢查它是否具有這個 的存取權 DispatcherObject

VerifyAccess 之間的差異 CheckAccess 在於會傳回 Boolean, CheckAccess 指定呼叫執行緒是否具有這個 DispatcherObject 的存取權,如果呼叫執行緒沒有這個 DispatcherObject 的存取權,則會 VerifyAccess 擲回例外狀況。

適用於