public void AddItem(FastPingItem fp) { fp.id = counter += 1; fpi.Add(fp); fail += fp.response == -1 ? 1 : 0; while (fpi.Count > 100) { fpi.Remove(fpi.OrderBy(i => i.id).First()); } this.Refresh(); }
//Fastping void fastping_Tick(object sender, EventArgs e) { fastping.Stop(); FastPingItem fp = new FastPingItem(); fp.host = fpHost.Text; using (Ping pinger = new Ping()) { try { string b = ""; while (b.Length < 32) { b += "a"; } byte[] buffer = Encoding.ASCII.GetBytes(b); PingReply reply = ConvertAndPingHost(fp.host, pinger, 1000, buffer); if (reply != null && reply.Status == IPStatus.Success) { fp.response = (int)reply.RoundtripTime; } else { fp.response = -1; } } catch { fp.response = -1; } } fpPanel.AddItem(fp); if (fpRunning) { fastping.Start(); } }