PeerWatcher.Stopped 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生于 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)
事件類型
TypedEventHandler<PeerWatcher,IInspectable>
Windows 需求
應用程式功能 |
proximity
|
備註
您可以呼叫 Stop 方法來停止 PeerWatcher 物件。 您可以註冊 Stopped 事件,以在 PeerWatcher 停止時收到通知。 您必須先等候 Stopped 事件,才能呼叫 Start 方法來重新開機 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.
});
}