DispatcherObject.CheckAccess Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Určuje, zda má volající vlákno přístup k tomuto DispatcherObject.
public:
bool CheckAccess();
public bool CheckAccess ();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean
Návraty
true
pokud má volající vlákno přístup k tomuto objektu; v opačném případě . false
Příklady
Následující příklad používá CheckAccess k určení, zda vlákno má přístup k vláknu, na které Button byl vytvořen. Metoda CheckAccess volání Button je volána k ověření přístupu k vláknu. Pokud má volající vlákno přístup, Button aktualizuje se pouhým přístupem k členům Button; jinak delegát, který přijímá Button jako argument, je publikován na Dispatcher straně Button.
// Uses the DispatcherObject.CheckAccess method to determine if
// the calling thread has access to the thread the UI object is on
private void TryToUpdateButtonCheckAccess(object uiObject)
{
Button theButton = uiObject as Button;
if (theButton != null)
{
// Checking if this thread has access to the object
if(theButton.CheckAccess())
{
// This thread has access so it can update the UI thread
UpdateButtonUI(theButton);
}
else
{
// This thread does not have access to the UI thread
// Pushing update method on the Dispatcher of the UI thread
theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new UpdateUIDelegate(UpdateButtonUI), theButton);
}
}
}
' Uses the DispatcherObject.CheckAccess method to determine if
' the calling thread has access to the thread the UI object is on
Private Sub TryToUpdateButtonCheckAccess(ByVal uiObject As Object)
Dim theButton As Button = TryCast(uiObject, Button)
If theButton IsNot Nothing Then
' Checking if this thread has access to the object
If theButton.CheckAccess() Then
' This thread has access so it can update the UI thread
UpdateButtonUI(theButton)
Else
' This thread does not have access to the UI thread
' Pushing update method on the Dispatcher of the UI thread
theButton.Dispatcher.BeginInvoke(DispatcherPriority.Normal, New UpdateUIDelegate(AddressOf UpdateButtonUI), theButton)
End If
End If
End Sub
Poznámky
Přístup k němu může získat pouze vlákno Dispatcher , na které DispatcherObjectbylo vytvořeno .
Jakékoli vlákno může zkontrolovat, zda má přístup k tomuto DispatcherObject.
Rozdíl mezi CheckAccess a VerifyAccess je, že CheckAccess vrátí logickou hodnotu, která určuje, zda má volající vlákno přístup k tomuto DispatcherObject a VerifyAccess vyvolá výjimku, pokud volající vlákno nemá přístup k tomuto DispatcherObject.
Volání této metody je stejné jako volání CheckAccess přidruženého objektu Dispatcher .