private void SearchOnlineComputers(object data) { SearchOnlineComputerData computerData = (SearchOnlineComputerData)data; object[] args = new object[2]; DataGridViewRow currentRow = computerData.Row; try { if (!cancelSearchOnlineComputers) { ADComputer computer = (ADComputer)currentRow.Cells["ComputerName"].Value; args[0] = currentRow; args[1] = "No"; if (computer.Ping(100)) { args[1] = "Yes"; } } } catch (Exception) { } try { if (!cancelSearchOnlineComputers) { DisplayOnLineStatusDelegate DisplayOnLineStatusHandler = new DisplayOnLineStatusDelegate(DisplayOnLineStatus); DisplayOnLineStatusHandler(args); } } catch (Exception) { } finally { computerData.countDown.Signal(); } }
private void HighLightOnLineComputers() { Logger.EnteringMethod(); string computerName = string.Empty; if (dGVComputer.Rows.Count > 0 && !cancelHighLightOnlineComputers) { DataGridViewRow[] rows = new DataGridViewRow[dGVComputer.Rows.Count]; dGVComputer.Rows.CopyTo(rows, 0); cancelSearchOnlineComputers = false; System.Threading.CountdownEvent countDown = new System.Threading.CountdownEvent(1); foreach (DataGridViewRow row in rows) { if (cancelHighLightOnlineComputers) { break; } countDown.AddCount(); SearchOnlineComputerData data = new SearchOnlineComputerData(); data.Row = row; data.countDown = countDown; System.Threading.ThreadPool.QueueUserWorkItem(SearchOnlineComputers, (object)data); } countDown.Signal(); countDown.Wait(dGVComputer.Rows.Count * 10000); Action action = () => { if (dGVComputer.SortedColumn != null && dGVComputer.SortedColumn.Name == "OnLine") { dGVComputer.Sort(dGVComputer.SortedColumn, (dGVComputer.SortOrder == SortOrder.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending); } }; this.Invoke(action); } }