PeerWatcher.EnumerationCompleted | enumerationcompleted event

Applies to Windows and Windows Phone

Occurs after a scan operation is complete and all peer apps within wireless range have been found.

Syntax


function onEnumerationCompleted(eventArgs) { /* Your code */ }
 
// addEventListener syntax
peerWatcher.addEventListener("enumerationcompleted", onEnumerationCompleted);
peerWatcher.removeEventListener("enumerationcompleted", onEnumerationCompleted);
 
- or -

peerWatcher.onenumerationcompleted = onEnumerationCompleted;


Event information

Delegate TypedEventHandler<PeerWatcher, Object>

Remarks

EnumerationCompleted event is raised when an enumeration looking for peer apps within range is complete.

  • Applies to Windows Phone

Note   Calling PeerFinder.ConnectAsync from within an EnumerationCompleted event handler will fail. Instead, call it outside of this event handler, for example, when the user has explicitly chosen to connect to a peer.


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;
    }
}



var _peerWatcher;
var _peerWatcherIsRunning = false;
var _peerFinderStarted = false;

// The list of peers discovered by the PeerWatcher.
var _discoveredPeers = new Array();

function peerFinder_StartPeerWatcher() {
    if (!_peerFinderStarted) {
        // PeerFinder must be started first.
       return;
    }

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

    try {
        if (!_peerWatcher)
        {
            _peerWatcher = PeerFinder.createWatcher();

            // Add PeerWatcher event handlers. Only add handlers once.
            peerWatcher.addEventListener("added", peerWatcher_Added); 
            peerWatcher.addEventListener("removed", peerWatcher_Removed); 
            peerWatcher.addEventListener("updated",  peerWatcher_Updated); 
            peerWatcher.addEventListener("enumerationcompleted", peerWatcher_EnumerationCompleted); 
            peerWatcher.addEventListener("stopped", peerWatcher_Stopped); 
        }

        // Empty the list of discovered peers.
        _discoveredPeers = new Array();

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

        _peerWatcherIsRunning = true;
    }
    catch (ex)
    {
        // Exceptions can occur if PeerWatcher.Start is called multiple times or
        // PeerWatcher.Start is called the PeerWatcher is stopping.
    }
}
    
function cleanup() {
    if (_peerWatcher) {
        // Remove event handlers.
        peerWatcher.removeEventListener("added", peerWatcher_Added); 
        peerWatcher.removeEventListener("removed", peerWatcher_Removed); 
        peerWatcher.removeEventListener("updated", peerWatcher_Updated); 
        peerWatcher.removeEventListener("enumerationCompleted", peerWatcher_EnumerationCompleted); 
        peerWatcher.removeEventListener("stopped", peerWatcher_Stopped); 

        _peerWatcher = null;
    }
}



function peerWatcher_EnumerationCompleted()
{
    if (_discoveredPeers.length == 0)
    {
        // No peers discovered for this enumeration.
    }
}


Requirements

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Networking.Proximity
Windows::Networking::Proximity [C++]

Metadata

Windows.winmd

See also

PeerWatcher
Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Samples
Proximity sample

 

 

Show:
© 2014 Microsoft