PeerWatcher.Stopped Evento
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Se produce cuando se ha detenido el objeto PeerWatcher .
// Register
event_token Stopped(TypedEventHandler<PeerWatcher, IInspectable const&> const& handler) const;
// Revoke with event_token
void Stopped(event_token const* cookie) const;
// Revoke with event_revoker
PeerWatcher::Stopped_revoker Stopped(auto_revoke_t, TypedEventHandler<PeerWatcher, IInspectable const&> const& handler) const;
public event TypedEventHandler<PeerWatcher,object> Stopped;
function onStopped(eventArgs) { /* Your code */ }
peerWatcher.addEventListener("stopped", onStopped);
peerWatcher.removeEventListener("stopped", onStopped);
- or -
peerWatcher.onstopped = onStopped;
Public Custom Event Stopped As TypedEventHandler(Of PeerWatcher, Object)
Tipo de evento
TypedEventHandler<PeerWatcher,IInspectable>
Requisitos de Windows
Características de aplicaciones |
proximity
|
Comentarios
Puede llamar al método Stop para detener el objeto PeerWatcher . Puede registrarse para que se informe al evento Stopped cuando peerWatcher se ha detenido. Debe esperar al evento Stopped para poder llamar al método Start para reiniciar PeerWatcher.
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_Stopped(PeerWatcher sender, object o)
{
_peerWatcherIsRunning = false;
var result = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
// Update UI now that the PeerWatcher is stopped.
});
}