DispatcherObject.CheckAccess Methode

Definitie

Bepaalt of de aanroepende thread toegang heeft tot dit DispatcherObject.

public:
 bool CheckAccess();
public bool CheckAccess();
member this.CheckAccess : unit -> bool
Public Function CheckAccess () As Boolean

Retouren

true als de aanroepende thread toegang heeft tot dit object; anders, false.

Voorbeelden

In het volgende voorbeeld wordt gebruikt CheckAccess om te bepalen of een thread toegang heeft tot de thread waarop een Button thread is gemaakt. De CheckAccess methode op de thread Button wordt aangeroepen om de toegang tot de thread te verifiëren. Als de aanroepende thread toegang heeft, wordt het Button bijgewerkt door alleen toegang te krijgen tot de leden van de Button; anders wordt een gemachtigde, die een Button als argument accepteert, op de van het DispatcherButton item geplaatst.

// 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

Opmerkingen

Alleen de thread waarop de Dispatcher thread is gemaakt, heeft toegang tot de DispatcherObject.

Elke thread kan controleren of deze toegang heeft tot deze DispatcherObjectthread.

Het verschil tussen CheckAccess en VerifyAccess is dat CheckAccess een Booleaanse waarde retourneert die aangeeft of de aanroepende thread toegang heeft tot dit DispatcherObject en VerifyAccess een uitzondering genereert als de aanroepende thread geen toegang heeft tot dit DispatcherObject.

Het aanroepen van deze methode is identiek aan het aanroepen CheckAccess van het bijbehorende Dispatcher object.

Van toepassing op