void _Start() { if (status == AdvertisementWatcherStatus.Started) { throw new InvalidOperationException("Watcher is already running"); } if (status == AdvertisementWatcherStatus.Stopping) { throw new InvalidOperationException("Watcher is still stopping"); } // following Windows API by setting Started status immediately status = AdvertisementWatcherStatus.Started; stopError = AdvertisementWatcherError.None; StartAsync().ContinueWith(t => { if (t.Status != TaskStatus.RanToCompletion) { status = AdvertisementWatcherStatus.Aborted; // TODO: more specific errors based on exception stopError = AdvertisementWatcherError.Unknown; Stop(); } }); }
void OnStopped(AdvertisementWatcherError error) { Stopped?.Invoke(this, new AdvertisementWatcherStoppedEventArgs(error)); }
internal AdvertisementWatcherStoppedEventArgs(AdvertisementWatcherError error) { Error = error; }
public AdvertismentWatcherException(AdvertisementWatcherError error) { Error = error; }