VerifyAccess Method

Dispatcher.VerifyAccess Method

Determines whether the calling thread has access to this Dispatcher.

Namespace: System.Windows.Threading
Assembly: WindowsBase (in windowsbase.dll)

public void VerifyAccess ()
public void VerifyAccess ()
public function VerifyAccess ()
You cannot use methods in XAML.

Exception typeCondition

InvalidOperationException

the calling thread does not have access to this Dispatcher.

Only the thread the Dispatcher is created on may access the Dispatcher.

This method is public; therefore, any thread can check to see whether it has access to the Dispatcher.

The difference between CheckAccess and VerifyAccess is CheckAccess returns a Boolean if the calling thread does not have access to the Dispatcher and VerifyAccess throws an exception.

The following example uses VerifyAccess to determine whether a thread has access to the thread that a Button was created on. The method takes an object as an argument, which is cast to a Button. The VerifyAccess method on the Dispatcher of the Button is called to verify access to the thread.

If the calling thread has access to the Dispatcher, the Button is updated by just accessing the members of the Button.

If the calling thread does not have access, an InvalidOperationException is thrown. This example catches the exception and pushes a delegate, which accepts a Button as an argument, onto the Dispatcher of the Button. This Dispatcher will do the work of updating the Button.

// Check if this thread has access to this object.
theButton.Dispatcher.VerifyAccess();

// The thread has access to the object, so update the UI.
UpdateButtonUI(theButton);

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2016 Microsoft