DispatcherObject.CheckAccess Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Çağıran iş parçacığının bu DispatcherObjectöğesine erişimi olup olmadığını belirler.
public:
bool CheckAccess();
public bool CheckAccess();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean
Döndürülenler
true çağıran iş parçacığının bu nesneye erişimi varsa; aksi takdirde , false.
Örnekler
Aşağıdaki örnek, bir iş parçacığının oluşturulduğu iş parçacığına CheckAccess erişimi olup olmadığını belirlemek için kullanırButton. CheckAccess üzerindeki yöntemiButton, iş parçacığına erişimi doğrulamak için çağrılır. Çağıran iş parçacığının erişimi varsa, öğesinin üyelerine erişilerek güncelleştirilir; aksi takdirde, bağımsız değişken olarak kabul eden bir Button temsilci öğesine gönderilir ButtonButton.DispatcherButton
// 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
Açıklamalar
Yalnızca üzerinde oluşturulduğu iş parçacığına DispatcherDispatcherObjecterişebilir.
Herhangi bir iş parçacığı, bu DispatcherObjectöğesine erişimi olup olmadığını denetleyebiliyor.
ile arasındaki CheckAccess fark, çağıran iş parçacığının VerifyAccess buna CheckAccess erişimi olup olmadığını belirten bir Boole döndürmesi ve DispatcherObject çağıran iş parçacığının bu öğesine erişimi yoksa bir özel durum oluşturmasıdırVerifyAccess.DispatcherObject
Bu yöntemin çağrılması, ilişkili CheckAccess nesnede çağrılmasıyla Dispatcher aynıdır.