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.

任何執行緒都可以檢查是否有此 DispatcherObject的存取權。Any thread can check to see whether it has access to this DispatcherObject.

CheckAccessVerifyAccess 之間的差異在於 CheckAccess 會傳回布林值,指定呼叫執行緒是否具有此 DispatcherObject 的存取權,而如果呼叫的執行緒沒有這個 VerifyAccess 的存取權,DispatcherObject會擲回例外狀況。The 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