/// <summary> /// 取消所有挂起的发送 Internet 控制消息协议 (ICMP) 回送消息并接收相应 ICMP 回送答复消息的异步请求。 /// </summary> public void SendAsyncCancel() { lock (this) { m_Ping.SendAsyncCancel(); } }
private void GeneratePing() { try { // Set options for transmission: // The data can go through 64 gateways or routers // before it is destroyed, and the data packet // cannot be fragmented. PingOptions options = new PingOptions(64, true); // Send the ping asynchronously. // Use the waiter as the user token. // When the callback completes, it can wake up this thread. pingSender.SendAsyncCancel(); pingSender.SendAsync(ipAddress, pingFrequency, pingBuffer, options); } catch (Exception ex) { Logger.Instance.LogMessage(TracingLevel.ERROR, $"GeneratePing failed: {ex}"); pingCanceled = true; } }
private void _onPingCompleted(object sender, PingCompletedEventArgs e) { System.Net.NetworkInformation.Ping myPing = (Ping)sender; pingList.Remove(myPing); UpdateProgressBarInvoke();//更新进度条 if (e.Reply.Status == IPStatus.Success) { string ipaddress = e.Reply.Address.ToString(); string ping = string.Format("{0}ms (Ttl:{1} Len:{2})", e.Reply.RoundtripTime.ToString(), e.Reply.Options.Ttl.ToString(), e.Reply.Buffer.Length.ToString()); string mac = GetMacAddress(ipaddress); string updateTime = this.GetDateTime(); onlineIPList.Add(ipaddress);//添加到在线IP列表 AddGridItemInvoke(skinDataGridView1, new IPAddressGridItem(ipaddress, "", updateTime, mac, "", false, false, "", ping)); } if (!e.Cancelled) { myPing.SendAsyncCancel(); } }
internal void Send() { ts.TraceInformation("Ping: Send to {0}", this.Target); pingSender.SendAsyncCancel(); pingSender.SendAsync(this.Target, (int)this.Timeout, this); }