Compartilhar via


PeerWatcher.EnumerationCompleted Evento

Definição

Ocorre depois que uma operação de verificação é concluída e todos os aplicativos pares dentro do intervalo sem fio são encontrados.

// Register
event_token EnumerationCompleted(TypedEventHandler<PeerWatcher, IInspectable const&> const& handler) const;

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

// Revoke with event_revoker
PeerWatcher::EnumerationCompleted_revoker EnumerationCompleted(auto_revoke_t, TypedEventHandler<PeerWatcher, IInspectable const&> const& handler) const;
public event TypedEventHandler<PeerWatcher,object> EnumerationCompleted;
function onEnumerationCompleted(eventArgs) { /* Your code */ }
peerWatcher.addEventListener("enumerationcompleted", onEnumerationCompleted);
peerWatcher.removeEventListener("enumerationcompleted", onEnumerationCompleted);
- or -
peerWatcher.onenumerationcompleted = onEnumerationCompleted;
Public Custom Event EnumerationCompleted As TypedEventHandler(Of PeerWatcher, Object) 

Tipo de evento

Requisitos do Windows

Funcionalidades do aplicativo
proximity

Comentários

O evento EnumerationCompleted é gerado quando uma enumeração que procura aplicativos pares dentro do intervalo é concluída.

Importante

Para aplicativos Windows Phone 8.x, a chamada de PeerFinder.ConnectAsync de dentro de um manipulador de eventos EnumerationCompleted falhará. Em vez disso, chame-o fora desse manipulador de eventos, por exemplo, quando o usuário tiver explicitamente escolhido se conectar a um par.

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_EnumerationCompleted(PeerWatcher sender, object o)
{
    var result = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
    {
        lock (this)
        {
            if (_discoveredPeers.Count == 0)
            {
                // No peers discovered for this enumeration.
            }
        }
    });
}

Aplica-se a

Confira também