From ab361bad98ecb279bffe474b2a60e6704ff0f7f8 Mon Sep 17 00:00:00 2001 From: Master T Date: Mon, 25 Nov 2013 15:39:14 +0100 Subject: [PATCH] ServiceBrowser: add Services property which is synchronized with the user events --- Tmds/MDns/ServiceBrowser.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tmds/MDns/ServiceBrowser.cs b/Tmds/MDns/ServiceBrowser.cs index 2531a21..dfd4d1c 100644 --- a/Tmds/MDns/ServiceBrowser.cs +++ b/Tmds/MDns/ServiceBrowser.cs @@ -56,6 +56,7 @@ public void StartBrowse(string serviceType) public QueryParameters QueryParameters { get; private set; } public SynchronizationContext SynchronizationContext { get; set; } public bool IsBrowsing { get; private set; } + public IEnumerator Services { get { return _services.GetEnumerator(); } } public event EventHandler ServiceAdded; public event EventHandler ServiceRemoved; @@ -78,6 +79,10 @@ internal void OnServiceAdded(ServiceInfo service) _serviceAnnouncements.Add(Tuple.Create(service.NetworkInterface.Id, service.Name), announcement); SynchronizationContextPost(o => { + lock (_services) + { + _services.Add(announcement); + } if (ServiceAdded != null) { ServiceAdded(this, new ServiceAnnouncementEventArgs(announcement)); @@ -93,6 +98,10 @@ internal void OnServiceRemoved(ServiceInfo service) SynchronizationContextPost(o => { announcement.IsRemoved = true; + lock (_services) + { + _services.Remove(announcement); + } if (ServiceRemoved != null) { ServiceRemoved(this, new ServiceAnnouncementEventArgs(announcement)); @@ -229,6 +238,7 @@ private void SynchronizationContextPost(SendOrPostCallback cb) } } + private readonly HashSet _services = new HashSet(); private readonly Dictionary, ServiceAnnouncement> _serviceAnnouncements = new Dictionary, ServiceAnnouncement>(); private readonly List _serviceTypes = new List(); private Dictionary _interfaceHandlers;