Partager via


PeerWatcher.Updated Événement

Définition

Se produit lorsque le DisplayName ou DiscoveryData d’une application homologue dans la plage sans fil a changé.

// Register
event_token Updated(TypedEventHandler<PeerWatcher, PeerInformation const&> const& handler) const;

// Revoke with event_token
void Updated(event_token const* cookie) const;

// Revoke with event_revoker
PeerWatcher::Updated_revoker Updated(auto_revoke_t, TypedEventHandler<PeerWatcher, PeerInformation const&> const& handler) const;
public event TypedEventHandler<PeerWatcher,PeerInformation> Updated;
function onUpdated(eventArgs) { /* Your code */ }
peerWatcher.addEventListener("updated", onUpdated);
peerWatcher.removeEventListener("updated", onUpdated);
- or -
peerWatcher.onupdated = onUpdated;
Public Custom Event Updated As TypedEventHandler(Of PeerWatcher, PeerInformation) 

Type d'événement

Configuration requise pour Windows

Fonctionnalités de l’application
proximity

Remarques

L’événement Mis à jour est déclenché lorsque displayName ou DiscoveryData d’une application homologue change. Vous pouvez utiliser la propriété Id pour identifier de manière unique l’application homologue et mettre à jour votre interface utilisateur.

Important

Pour Windows Phone applications 8.x, l’appel de PeerFinder.ConnectAsync à partir d’un gestionnaire d’événements mis à jour échoue. Au lieu de cela, appelez-le en dehors de ce gestionnaire d’événements, par exemple, lorsque l’utilisateur a explicitement choisi de se connecter à un homologue.

private PeerWatcher _peerWatcher;
private bool _peerWatcherIsRunning = false;
private bool _peerFinderStarted = false;

// The list of peers discovered by the PeerWatcher.
ObservableCollection<PeerInformation> _discoveredPeers = new ObservableCollection<PeerInformation>();
void PeerFinder_StartPeerWatcher(object sender, RoutedEventArgs e)
{
    if (!_peerFinderStarted)
    {
        // PeerFinder must be started first.
        return;
    }

    if (_peerWatcherIsRunning)
    {
        // PeerWatcher is already running.
        return;
    }

    try
    {
        if (_peerWatcher == null)
        {
            _peerWatcher = PeerFinder.CreateWatcher();

            // Add PeerWatcher event handlers. Only add handlers once.
            _peerWatcher.Added += PeerWatcher_Added;
            _peerWatcher.Removed += PeerWatcher_Removed;
            _peerWatcher.Updated += PeerWatcher_Updated;
            _peerWatcher.EnumerationCompleted += PeerWatcher_EnumerationCompleted;
            _peerWatcher.Stopped += PeerWatcher_Stopped;
        }

        // Empty the list of discovered peers.
        _discoveredPeers.Clear();

        // Start the PeerWatcher.
        _peerWatcher.Start();

        _peerWatcherIsRunning = true;
    }
    catch (Exception ex)
    {
        // Exceptions can occur if PeerWatcher.Start is called multiple times or
        // PeerWatcher.Start is called the PeerWatcher is stopping.
    }
}

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
    if (_peerWatcher != null)
    {
        // Remove event handlers.
        _peerWatcher.Added -= PeerWatcher_Added;
        _peerWatcher.Removed -= PeerWatcher_Removed;
        _peerWatcher.Updated -= PeerWatcher_Updated;
        _peerWatcher.EnumerationCompleted -= PeerWatcher_EnumerationCompleted;
        _peerWatcher.Stopped -= PeerWatcher_Stopped;

        _peerWatcher = null;
    }
}
private void PeerWatcher_Updated(PeerWatcher sender, PeerInformation peerInfo)
{
    var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
    {
        lock (this)
        {
            // Find and update the peer in the list of discovered peers.
            for (int i = 0; i < _discoveredPeers.Count; i++)
            {
                if (_discoveredPeers[i].Id == peerInfo.Id)
                {
                    _discoveredPeers[i] = peerInfo;
                }
            }
        }
    });
}

S’applique à

Voir aussi