DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess DispatcherObject.VerifyAccess Method

定義

請強制執行可以存取這個 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的執行緒可以DispatcherObject存取。Only 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.

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

適用於