/// <summary> /// Stops this UPnP network tracker's activity, i.e. closes the UPnP network listener and clears all /// <see cref="KnownRootDevices"/>. /// </summary> public void Close() { lock (_cpData.SyncObj) { if (!_active) { return; } _active = false; foreach (RootEntry entry in _cpData.SSDPController.RootEntries) { RootDescriptor rd = GetRootDescriptor(entry); if (rd == null) { continue; } InvalidateDescriptor(rd); } SSDPClientController ssdpController = _cpData.SSDPController; ssdpController.Close(); ssdpController.RootDeviceAdded -= OnSSDPRootDeviceAdded; ssdpController.RootDeviceRemoved -= OnSSDPRootDeviceRemoved; ssdpController.DeviceRebooted -= OnSSDPDeviceRebooted; ssdpController.DeviceConfigurationChanged -= OnSSDPDeviceConfigurationChanged; _cpData.SSDPController = null; foreach (DescriptionRequestState state in _pendingRequests) { state.Request.Abort(); } _pendingRequests.Clear(); } }
/// <summary> /// Starts this UPnP network tracker. After the tracker is started, its <see cref="RootDeviceAdded"/> and /// <see cref="RootDeviceRemoved"/> events will begin to be raised when UPnP devices become available at the network of when /// UPnP devices disappear from the network. /// </summary> public void Start() { lock (_cpData.SyncObj) { if (_active) { throw new IllegalCallException("UPnPNetworkTracker is already active"); } _active = true; SSDPClientController ssdpController = new SSDPClientController(_cpData); ssdpController.RootDeviceAdded += OnSSDPRootDeviceAdded; ssdpController.RootDeviceRemoved += OnSSDPRootDeviceRemoved; ssdpController.DeviceRebooted += OnSSDPDeviceRebooted; ssdpController.DeviceConfigurationChanged += OnSSDPDeviceConfigurationChanged; _cpData.SSDPController = ssdpController; ssdpController.Start(); ssdpController.SearchAll(null); } }