DispatcherObject.CheckAccess Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Determina se o thread que chama tem acesso a este DispatcherObject.
public:
bool CheckAccess();
public bool CheckAccess();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean
Devoluções
true se o thread que chama tiver acesso a este objeto; caso contrário, false.
Exemplos
O exemplo seguinte serve CheckAccess para determinar se um thread tem acesso ao thread onde a Button foi criado. O CheckAccess método no Button é chamado para verificar o acesso ao thread. Se o fio que chama tiver acesso, o Button é atualizado apenas acedendo aos membros do Button; caso contrário, um delegado, que aceita a Button como argumento, é publicado no Dispatcher de 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
Observações
Apenas o thread em que foi criado Dispatcher pode aceder ao DispatcherObject.
Qualquer tópico pode verificar se tem acesso a isto DispatcherObject.
A diferença entre CheckAccess e é que CheckAccess devolve um Booleano que especifica se o thread que chama tem acesso a isto DispatcherObject e VerifyAccess lança uma exceção se o thread que chama não tiver acesso a este DispatcherObjectVerifyAccess .
Chamar este método é idêntico a chamar CheckAccess o objeto associado Dispatcher .