private void worker_QueryInfo(object sender, DoWorkEventArgs e) { string computer = (string)e.Argument; Console.WriteLine("Computer = " + computer); Ping ping = new Ping(); PingReply pingReply = null; try { pingReply = ping.Send(computer); } catch (PingException pingException) { Console.WriteLine("Error! Bad hostname! Aborting..."); (sender as BackgroundWorker).ReportProgress(-1); return; } if (pingReply.Status == IPStatus.Success) { (sender as BackgroundWorker).ReportProgress(1); ComputerInfo computerInfo = infoGetter.GetComputerInfo(computer); (sender as BackgroundWorker).ReportProgress(2, computerInfo); List <MonitorInfo> monitorInfos = infoGetter.GetMonitorInfo(computer); (sender as BackgroundWorker).ReportProgress(3, monitorInfos); List <DeviceInfo> deviceInfos = infoGetter.GetDeviceInfoRegistry(computer); (sender as BackgroundWorker).ReportProgress(4, deviceInfos); (sender as BackgroundWorker).ReportProgress(5, deviceInfos); } }
private void worker_QueryInfo(object sender, DoWorkEventArgs e) { try { Ping ping = new Ping(); PingReply pingReply = null; try { pingReply = ping.Send((string)e.Argument, 1000); } catch (PingException pingException) { Console.WriteLine("Error! Bad hostname: " + (string)e.Argument + ". Skipping..."); ping.Dispose(); return; } if (pingReply.Status != IPStatus.Success) { ping.Dispose(); return; } ping.Dispose(); InfoGetter infoGetter = new InfoGetter(); infoGetter.USBIDSPath = globalArgs.usbIDSPath; if (!infoGetter.connectionTest((string)e.Argument)) { Console.WriteLine("WMI/CIM query failed on " + (string)e.Argument + ". Skipping..."); return; } if (!infoGetter.registryTest((string)e.Argument)) { Console.WriteLine("Registry query failed on " + (string)e.Argument + ". Skipping..."); return; } string computer = (string)e.Argument; ComputerInfo computerInfo = infoGetter.GetComputerInfo(computer); List <MonitorInfo> monitorInfos = infoGetter.GetMonitorInfo(computer); monitorInfos = infoGetter.FilterMonitorInfo(monitorInfos, globalArgs); List <DeviceInfo> deviceInfos = infoGetter.GetDeviceInfoRegistry(computer); deviceInfos = infoGetter.FilterDeviceInfo(deviceInfos, globalArgs); List <CSVInfo> returnInfo = writer.IngestData(computerInfo, monitorInfos, deviceInfos); e.Result = returnInfo; } catch { Console.WriteLine("Unknown unhandled error querying " + e.Argument + ". Aborting..."); e.Result = null; } }