string FindDevice() { BeginStep("Transmit multicast PROBE message"); LogStepEvent("Retransmit once per 5 seconds until a response is received or timeout (no more than 50 times)"); DeviceFinder finder = new DeviceFinder(_nic.IP, _semaphore.StopEvent); finder.OnProgress += finder_OnProgress; Uri uri = new Uri(_cameraAddress); System.Net.IPAddress ip = System.Net.IPAddress.Parse(uri.Host); DeviceFinder.FindDeviceDelegate del = new DeviceFinder.FindDeviceDelegate(finder.ProbeDevice); IAsyncResult result = del.BeginInvoke(ip, 50, 5000, null, null); WaitHandle[] handles = new WaitHandle[] { _semaphore.StopEvent, result.AsyncWaitHandle }; int handle = WaitHandle.WaitAny(handles); if (handle == 0) { finder.Stop(); throw new StopEventException(); } string data = del.EndInvoke(result); if (!string.IsNullOrEmpty(data)) { LogStepEvent(string.Format("PROBE match message: {0}", data)); } StepPassed(); Assert(data != null, "Device not found", "Check that answer has been received"); return(data); }