private void DoPing() { while (!_isStop) { PingReply rep = LanMachine.Ping(_ip, 1000); string msg = GetMessage(rep); try { if (!this.IsDisposed && !_isStop) { this.Invoke(new MethodInvoker(delegate { if (rtbInfo.Text.Length > 8000) { rtbInfo.Text = ""; } rtbInfo.Text += msg + "\n\n"; rtbInfo.SelectionStart = rtbInfo.Text.Length; })); } } catch { } Thread.Sleep(1000); } }
/// <summary> /// 扫描机器 /// </summary> /// <param name="machine"></param> private void ScanMachine(object objMachine) { LanMachine machine = objMachine as LanMachine; try { if (machine.Ping(_speed.Timeout).Status == IPStatus.Success) { try { machine.HostName = LanMachine.GetHostName(machine.IP); } catch { machine.HostName = machine.IP.ToString(); } try { machine.Mac = MacInfo.GetRemoteMac(machine.IP.ToString()); } catch { } AddToGrid(machine, dgMembers); } } catch (Exception ex) { } finally { try { if (!this.IsDisposed && !_isStop) { this.Invoke(new MethodInvoker(delegate { tspbScan.Value++; tsProcess.Text = (tspbScan.Value * 100 / tspbScan.Maximum).ToString() + "%"; if (tspbScan.Value >= tspbScan.Maximum) { DoScaning(false); } })); } } catch { } } }