/// <summary> /// Find the available chromecast receivers /// </summary> /// <typeparam name="cancellationToken">Enable to cancel the operation before timeout</typeparam> /// <typeparam name="timeOut">Define custom timeout when required, default is 2000 ms</typeparam> /// <returns>a collection of chromecast receivers</returns> public async Task <IEnumerable <ChromecastReceiver> > FindReceiversAsync(CancellationToken cancellationToken) { if (_serviceBrowser.IsBrowsing) { _serviceBrowser.StopBrowse(); } _serviceBrowser.StartBrowse("_googlecast._tcp"); while (!cancellationToken.IsCancellationRequested) { await Task.Delay(100); } _serviceBrowser.StopBrowse(); return(DiscoveredDevices); }
private void scanTimer_Tick(object sender, EventArgs e) { scanTimer.Stop(); serviceBrowser.StopBrowse(); this.Invoke(new MethodInvoker(delegate { if (buttonList.Count == 0) { message.Text = "Couldn't find any esprgb devices in your network"; } resScnDevice.Visible = true; })); }
private void refresh_mdns_Click(object sender, RoutedEventArgs e) { new Action(() => { node.Log("开始扫描MDNS"); ServiceBrowser browser = new ServiceBrowser(); SynchronizationContext context = new SynchronizationContext(); browser.StartBrowse("*", context); Thread.Sleep(3000); browser.StopBrowse(); node.Log("更新结果"); Dispatcher.Invoke(() => mdns_result.ItemsSource = browser.Services); }).ThreadStart(() => Dispatcher.Invoke(() => refresh_mdns.IsEnabled = false), () => Dispatcher.Invoke(() => refresh_mdns.IsEnabled = true)); }
/// <summary> /// Discover all the nanoleaf systems on the network /// </summary> /// <param name="timeoutInMs">the discover scan timeout</param> /// <returns>list of light systems</returns> public async Task <IList <ILightSystem> > DiscoverAsync(int timeoutInMs = 5000) { var systems = new List <ILightSystem>(); var systemsLock = new object(); var discover = new ServiceBrowser(); discover.ServiceAdded += (object sender, ServiceAnnouncementEventArgs e) => { lock (systemsLock) { systems.AddRange(e.Announcement.Addresses .Select(addr => new IPEndPoint(addr, e.Announcement.Port)) .Select(endpoint => new NanoleafLightSystem(endpoint))); } }; discover.StartBrowse(ServiceName); await Task.Delay(timeoutInMs); discover.StopBrowse(); return(systems); }
public void StopDiscovery() { serviceBrowser.StopBrowse(); }
public void Dispose() { serviceBrowser.StopBrowse(); Available.Clear(); }
private void btnOK_Click(object sender, EventArgs e) { // clean before exit serviceBrowser.StopBrowse(); this.Close(); }