DispatcherObject.CheckAccess Метод
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Определяет, имеет ли вызывающий поток доступ к этому DispatcherObject.
public:
bool CheckAccess();
public bool CheckAccess();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean
Возвращаемое значение
true Значение , если вызывающий поток имеет доступ к этому объекту; falseв противном случае .
Примеры
В следующем примере определяетсяCheckAccess, имеет ли поток доступ к созданному потоку.Button CheckAccess Метод Button вызывается для проверки доступа к потоку. Если вызывающий поток имеет доступ, Button он обновляется путем простого доступа к членам Buttonобъекта; в противном случае делегат, который принимает в Button качестве аргумента, размещается в Dispatcher объекте 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
Комментарии
Доступ к ней может получить Dispatcherтолько потокDispatcherObject, созданный.
Любой поток может проверить, имеет ли он доступ к этому DispatcherObject.
Разница между CheckAccess и VerifyAccess заключается в том, что CheckAccess возвращает логическое значение, указывающее, имеет ли вызывающий поток доступ к этому DispatcherObject и VerifyAccess создает исключение, если вызывающий поток не имеет доступа к этому DispatcherObject.
Вызов этого метода идентичен вызову CheckAccess связанного Dispatcher объекта.