[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Determines whether the calling thread has access to this object.
Assembly: System.Windows (in System.Windows.dll)
If it is the same thread, returns true. You can perform actions on that DependencyObject. This might include setting properties, calling methods and so on.
If the current threading context is not the creating thread, returns false. Nearly all attempts to perform actions that attempt to change values on the DependencyObject will raise exceptions in this circumstance. However, you can retrieve the Dispatcher value from that DependencyObject, and use the Dispatcher API to invoke the action. For more information, see Dispatcher.
Any thread can check to see if it has access to a particular DependencyObject.
If returns false, this typically means that you are attempting to access a DependencyObject on the main UI thread, from a threading context that is not the main UI thread.
BackgroundWorker is a possible option for delegating threads to perform actions that are not using the main UI thread.
The following code example demonstrates how to use this method to check whether an action can be performed against a DependencyObject on the UI thread, and uses BeginInvoke in cases where returns false.
Private Delegate Sub AddTextDelegate(ByVal p As Panel, ByVal text As String) Private Sub AddText(ByVal p As Panel, ByVal text As String) p.Children.Clear() Dim t As New TextBlock t.Text = text p.Children.Add(t) End Sub Private Sub TestBeginInvokeWithParameters(ByVal p As Panel) If p.Dispatcher.CheckAccess() _ Then AddText(p, "Added directly.") _ Else p.Dispatcher.BeginInvoke(New AddTextDelegate( _ AddressOf AddText), p, "Added by Dispatcher.") End Sub