Difference between FindServicesAsync, FindDevicesAsync and instance Start

Oct 17, 2011 at 3:04 AM
Edited Oct 17, 2011 at 3:40 AM

Hi all,

Are there any differences between the static Discovery.FindDevicesAsync, Discovery.FindServicesAsync and the instance Start()?

If I use the static Discovery.FindServicesAsync, I can find 3 services for my router.

If I use the static Discovery.FindDevicesAsync, I can only find 1 service for my router.

If I use the instance Start() as shown in the following code, only 1 service is found too for the same router.

Discovery UPnPDiscovery = new Discovery(null, AddressFamilyFlags.IPvBoth, false);
UPnPDiscovery.DeviceAdded += new DeviceAddedEventHandler(UPnPDiscovery_DeviceAdded);
UPnPDiscovery.DeviceRemoved += new DeviceRemovedEventHandler(UPnPDiscovery_DeviceRemoved);
UPnPDiscovery.SearchComplete += new SearchCompleteEventHandler(UPnPDiscovery_SearchComplete);

I have tried version 1.0, 1.1 and 1.4 and the results are the same. I don't want to use the static Discovery.FindServicesAsync since I can't stop the discovery thread immediately when my program stops. So I prefer the instance one since it provides Stop().

Thank you very much.

Oct 17, 2011 at 6:38 AM

I think I know why now. I have to enumerate the devices and services recursively if I use Start() or FindDevicesAsync

Oct 17, 2011 at 1:41 PM
Edited Oct 17, 2011 at 1:44 PM


Sorry it took me a while to get back to you.

Looks like you have worked it out for yourself :), the static methods are more convenient coding wise, but dont give as much control, you can only specify a timeout rather than being able to cancel manually, however, they are a little more convenient as they will return the devices and services as a single enumerable for each call. Where as with the instance Start() method you must use the event handlers.

As you have also found, the FindDevicesAsync will only return the devices themselves, so you have to do a deep search for services.

So it looks like you have all it worked out :) Let me know if you have any more questions!