public static void PingCompletedCallback (object sender, PingCompletedEventArgs e) { // If the operation was canceled, display a message to the user. if (e.Cancelled) { Console.WriteLine ("Ping canceled."); // Let the main thread resume. // UserToken is the AutoResetEvent object that the main thread // is waiting for. ((AutoResetEvent) e.UserState).Set (); } // If an error occurred, display the exception to the user. if (e.Error != null) { Console.WriteLine ("Ping failed:"); Console.WriteLine (e.Error.ToString ()); // Let the main thread resume. ((AutoResetEvent) e.UserState).Set (); } PingReply reply = e.Reply; DisplayReply (reply); // Let the main thread resume. ((AutoResetEvent) e.UserState).Set (); }
private void HandleConnectionPingCompleted(object sender, PingCompletedEventArgs e) { if (m_TcpClient != null) { Disconnect(); } m_TcpClient = new TcpClient(); m_TcpClient.BeginConnect(Hostname, Port, ConnectComplete, null); }
/// <summary> /// Ping complete event. /// </summary> /// <param name="sender">Current sender.</param> /// <param name="e">Event arguments.</param> void OnPingCompleted(object sender, PingCompletedEventArgs e) { // Check to see if an error occurred. If no error, then display // the address used and the ping time in milliseconds. if (e.Error == null) { // If the operation was cancelled. if (e.Cancelled) { txtPingResult.Text += " Ping cancelled. \r\n"; } else { // If the ping request succeded. if (e.Reply.Status == IPStatus.Success) { // Show the result of the // ping request. txtPingResult.Text += " " + e.Reply.Address.ToString() + " " + e.Reply.RoundtripTime.ToString( NumberFormatInfo.CurrentInfo) + "ms" + "\r\n"; } else { // If the ping was not succesful // then get ip status. txtPingResult.Text += " " + GetStatusString(e.Reply.Status) + "\r\n"; } } } else { // Otherwise display the error. txtPingResult.Text += " Ping error.\r\n"; MessageBox.Show("An error occurred while sending this ping. " + e.Error.InnerException.Message); } // Enable the send ping button // when the ping was complete. btnPing.Enabled = true; }
private void PingCompleted(object sender, PingCompletedEventArgs e) { string ip = (string)e.UserState; if (e.Reply != null && e.Reply.Status == IPStatus.Success) { string hostname = GetHostName(ip); string[] arr = new string[3]; arr[0] = ip; arr[1] = hostname; if (!containsValue(ips, arr[0])) { ips.Add(arr[0]); ids.Add(arr[1]); } } }
private void myPingCompletedCallBack(object sender, PingCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { if (notifyIcon1.Visible == true) { notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\circle_red.ico"); } else { lblStatus.Text = "Offline"; picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\red.png"); online = false; } } if (e.Reply.Status == IPStatus.Success) { if (notifyIcon1.Visible == true) { notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\btn_green.ico"); } else { lblStatus.Text = "Online"; picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\green_ball.png"); online = true; } } else { if (notifyIcon1.Visible == true) { notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\btn_red.ico"); } else { lblStatus.Text = "Offline"; picStatus.Image = Image.FromFile(Directory.GetCurrentDirectory() + "\\red.png"); online = false; } } }
private void OnPingCompleted(object sender, PingCompletedEventArgs e) { if (PingReplies.Count() > MaxReply) { Dispatcher.Invoke(() => PingReplies.RemoveAt(PingReplies.Count - 1)); } LastReply = new PingReplyWrapper(e.Reply); Dispatcher.Invoke(() => PingReplies.Insert(0, LastReply)); CalculateAverage(); CalculatePacketLoss(); Task.Delay(PingInterval).ContinueWith(_ => { if (IsRunning) { StartPing(); } }); }
internal void PingComplete(object sender, PingCompletedEventArgs e) { if (e.Cancelled) { ts.TraceInformation("Ping was canceled"); } else if (e.Error != null) { ts.TraceEvent(TraceEventType.Error, 1, "An error occured: {0}", e.Error); this.context.EvError(); } else { PingReply pingResponse = e.Reply; ShowPingResults(pingResponse); } }
private void p_PingCompleted(object sender, PingCompletedEventArgs e) { var ip = (string)e.UserState; if (e.Reply != null && e.Reply.Status == IPStatus.Success) { string name; if (true) { try { var hostEntry = Dns.GetHostEntry(ip); name = hostEntry.HostName; } catch (SocketException) { name = "?"; } _logger.Info($"{ip} ({name}) is up: ({e.Reply.RoundtripTime} ms)"); } else { _logger.Info($"{ip} is up: ({e.Reply.RoundtripTime} ms)"); } Interlocked.Increment(ref _upCount); ReachableAdress.Add(new Host { Ip = ip, Name = name, RoundtripTime = e.Reply.RoundtripTime }); } else if (e.Reply == null) { _logger.Info($"Pinging {ip} failed. (Null Reply object?)"); } var notify = _upCount % 10 == 0; if (notify || ip.EndsWith("254")) { OnPropertyChanged(nameof(ReachableAdress)); } }
void pinger_PingCompleted(object sender, PingCompletedEventArgs e) { try { object[] args = (object[])e.UserState; DateTime time = (DateTime)args[0]; long pingNum = (long)args[1]; PingGraphControl graph = (PingGraphControl)args[2]; int pingTargetId = (int)args[3]; // Do not assume the pingTargets or pingGraphs containers will have this key! IPAddress remoteHost = (IPAddress)args[4]; Ping pinger = (Ping)args[5]; pinger.PingCompleted -= pinger_PingCompleted; PingInstancePool.Recycle(pinger); if (e.Cancelled) { graph.AddPingLogToSpecificOffset(pingNum, new PingLog(time, 0, IPStatus.Unknown)); Interlocked.Increment(ref failedPings); return; } graph.AddPingLogToSpecificOffset(pingNum, new PingLog(time, (short)e.Reply.RoundtripTime, e.Reply.Status)); if (e.Reply.Status != IPStatus.Success) { Interlocked.Increment(ref failedPings); if (clearedDeadHosts && pingTargets.ContainsKey(pingTargetId)) { CreateLogEntry("" + time.ToString(dateFormatString) + ", " + remoteHost.ToString() + ": " + e.Reply.Status.ToString()); } } else { if (!clearedDeadHosts) { pingTargetHasAtLeastOneSuccess[pingTargetId] = true; } Interlocked.Increment(ref successfulPings); } } finally { UpdatePingCounts(Interlocked.Read(ref successfulPings), Interlocked.Read(ref failedPings)); } }
private void PingCompletedCallback(object sender, PingCompletedEventArgs e) { if (e.Cancelled) { ((Ping)sender).PingCompleted -= PingCompletedCallback; return; } PingReply reply = e.Reply; DisplayReply((string)e.UserState, reply); ((Ping)sender).PingCompleted -= PingCompletedCallback; //speed.Plot1.InvalidatePlot(true); /*if (continuous) { * await Task.Delay(1000); * doPing((Ping)sender, ((string)e.UserState)); * }*/ }
private static void PingCompleted(object sender, PingCompletedEventArgs e) { string ip = (string)e.UserState; if (e.Reply != null && e.Reply.Status == IPStatus.Success) { string hostName = GetHostName(ip); string macAddress = GetMacAddress(ip); var result = new PingResult() { IP = ip, HostName = hostName, MacAddress = macAddress }; Console.Out.WriteLine($"Ping Result: {ip} - {hostName} - {macAddress}"); } }
private void pingTest_Complete(object sender, PingCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show("MadCow was unable to detect an active Internet connection." + "\nMadCow has an strong Internet dependency and wont work properly under this conditions.", "[FATAL ERROR] - No Internet Connection was found", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { PingReply pingResponse = e.Reply; if (pingResponse.Status == IPStatus.Success) { Console.WriteLine("Internet connectivity found."); } else { MessageBox.Show("MadCow was unable to detect an active Internet connection." + "\nMadCow has an strong Internet dependency and wont work properly under this conditions.", "[FATAL ERROR] - No Internet Connection was found", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e) { if (e.Reply.Status == IPStatus.Success) { string reply = e.Reply.Address.ToString(); if (computerInfo.Keys.Contains(reply)) { try { computerInfo[reply].machinename = Dns.GetHostEntry(IPAddress.Parse(reply)).HostName; computerInfo[reply].status = ComputerStatus.ON_LINE; Kii.Invoke(computerInfo[reply]); } catch (Exception err) { } } } }
private void Pinger_PingCompleted(object sender, PingCompletedEventArgs e) { try { if (e.Reply != null) { chart1.AddPoint(e.Reply.Status); } else { chart1.AddPoint(IPStatus.BadDestination); } pinger.SendAsyncCancel(); } catch (Exception error) { Console.WriteLine("void Pinger_PingCompleted error: " + error.Message); } }
/// <summary> /// Called when ping completed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The /// <see cref="System.Net.NetworkInformation.PingCompletedEventArgs"/> /// instance containing the event data.</param> private void OnPingCompleted(object sender, PingCompletedEventArgs e) { if (!e.Cancelled) { if (e.Reply.Status != IPStatus.Success) { SynchronizationContext syncContext = e.UserState as SynchronizationContext; syncContext.Post( state => { this.errors[Reflect.GetPropertyName(() => this.IpAddress)] = string.Format(Resources.PingFailed, e.Reply.Status.ToString()); this.OnPropertyChanged(Reflect.GetPropertyName(() => this.IpAddress)); }, null); } } }
private void PingCompletedCallback(object sender, PingCompletedEventArgs e, Chart chart, String chartname) { try { foreach (Label lbl in panel1.Controls.OfType <Label>()) { if (lbl.Name == chartname) { lbl.Text = " (X) " + chartname + " -> " + e.Reply.Address.ToString() + " : " + e.Reply.Status.ToString() + " @ " + e.Reply.RoundtripTime; } } if (e.Reply.Status != IPStatus.Success) { //tbresults.Text += Environment.NewLine + e.Reply.Address.ToString() + " : "+ e.Reply.Status.ToString(); chart.Series[0].Points.Add(80).Color = Color.Red; } else { Color col = new Color(); col = Color.Green; if (e.Reply.RoundtripTime < 20) { col = Color.Green; } else if (e.Reply.RoundtripTime >= 20 && e.Reply.RoundtripTime <= 35) { col = Color.Yellow; } else if (e.Reply.RoundtripTime > 35) { col = Color.BlueViolet; } chart.Series[0].Points.Add(e.Reply.RoundtripTime).Color = col; } }catch (NullReferenceException) { // in case the pinger was deleted while async task was running and this is the callback // Nothing } }
public static async Task SendAsyncs_ReuseInstance_Hostname() { IPAddress localIpAddress = await TestSettings.GetLocalIPAddress(); using (Ping p = new Ping()) { TaskCompletionSource <bool> tcs = null; PingCompletedEventArgs ea = null; p.PingCompleted += (s, e) => { ea = e; tcs.TrySetResult(true); }; Action reset = () => { ea = null; tcs = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); }; // Several normal iterations for (int i = 0; i < 3; i++) { reset(); p.SendAsync(TestSettings.LocalHost, null); await tcs.Task; Assert.NotNull(ea); Assert.Equal(IPStatus.Success, ea.Reply.Status); Assert.True(ea.Reply.Address.Equals(localIpAddress)); } // Several canceled iterations for (int i = 0; i < 3; i++) { reset(); p.SendAsync(TestSettings.LocalHost, null); p.SendAsyncCancel(); // will block until operation can be started again } await tcs.Task; Assert.True(ea.Cancelled ^ (ea.Error != null) ^ (ea.Reply != null)); } }
public void KoniecPing(object sender, PingCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { listBox1.Items.Add("Błąd: Operacja ptrzerwana bądź nieprawisłowy adres "); ((IDisposable)(Ping)sender).Dispose(); return; } PingReply odpowiedz = e.Reply; if (odpowiedz.Status == IPStatus.Success) { listBox1.Items.Add("Odpowiedź z " + odpowiedz.Address.ToString() + " bajtów=" + odpowiedz.Buffer.Length + " ms TTL=" + odpowiedz.Options.Ttl); } else { listBox1.Items.Add("Błąd: Brak odpowiedzi z " + e.Reply.Address + " : " + odpowiedz.Status); } ((IDisposable)(Ping)sender).Dispose(); }
private void OnPingCompleted(object sender, PingCompletedEventArgs e) { ProcessNode(e.Reply.Address, e.Reply.Status); _options.Ttl += 1; if (!this.IsDone) { lock (lockerobj) { if (_localPing == null) { ProcessNode(_destination, IPStatus.Unknown); } else { _localPing.SendAsync(_destination, _timeOut, Buffer, _options, null); } } } }
private void PingRoundCompleted(object sender, PingCompletedEventArgs ev) { if (ev.Cancelled) { PingCompleted?.Invoke("Пинг отменён.", _configProtocol); ((AutoResetEvent)ev.UserState).Set(); } if (ev.Error != null) { PingCompleted?.Invoke($"Ошибка пинга: {ev.Error}", _configProtocol); ((AutoResetEvent)ev.UserState).Set(); } PingReply pingReply = ev.Reply; var replyLog = $"{DateTime.Now:dd MMMM yyyy HH:mm:ss} {_host} {pingReply.Status}"; ((AutoResetEvent)ev.UserState).Set(); PingCompleted?.Invoke(replyLog, _configProtocol); }
public void EndPing(object sender, PingCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { this.messages.Add("Błąd : Operacja przerwana bądź nieprawidłowy adres"); ((IDisposable)(Ping)sender).Dispose(); return; } PingReply reply = e.Reply; if (reply.Status == IPStatus.Success) { this.messages.Add("Odpowiedz z " + reply.Address.ToString() + " bajtow " + reply.Buffer.Length + " czas " + reply.RoundtripTime + " TTL " + reply.Options.Ttl); } else { this.messages.Add("Błąd " + e.Reply.Address + " " + reply.Status); } ((IDisposable)(Ping)sender).Dispose(); }
private static void PingCompletedCallback(object sender, PingCompletedEventArgs e) { if (e.Cancelled) { Console.WriteLine("Ping canceled."); } if (e.Error != null) { Console.WriteLine("Ping failed:"); Console.WriteLine(e.Error.ToString()); } else { PingReply reply = e.Reply; DisplayReply(reply); } ((AutoResetEvent)e.UserState).Set(); }
/// <summary> /// Ping结束事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Ping_PingCompleted(object sender, PingCompletedEventArgs e) { //触发Mesh设备列表进行更新 string ip = (string)e.UserState; if (e.Reply.Status == IPStatus.Success) { logger.Info(string.Format("Ping\"{0}\":{1}", ip, e.Reply.Status.ToString())); } string status = e.Reply.Status == IPStatus.Success ? "在线" : "离线"; if (ucGISVideo != null) { ucGISVideo.UpdateMeshStatus(ip, status); } if (ucAudioVideoProcess != null) { ucAudioVideoProcess.UpdateMeshStatus(ip, status); } }
private void OnPingCompleted(object sender, PingCompletedEventArgs e) { if (!this.cancel) { this.ProcessHop(e.Reply.Address, e.Reply.Status); if (e.Reply.Status != IPStatus.TimedOut) { this.pingOptions.Ttl++; } if (!this.Idle) { lock (this) { this.ping.SendAsync(this.destinationIP, this.HopTimeOut, this.buffer, this.pingOptions, null); } } } }
private void PingComplete(object sender, PingCompletedEventArgs e) { PingReply Reply; if (e.Cancelled) { Console.WriteLine("Ping Cencelled"); ((AutoResetEvent)e.UserState).Set(); } else if (e.Error != null) { Console.WriteLine("Fatal error!!!" + e.Error); ((AutoResetEvent)e.UserState).Set(); } else { Reply = e.Reply; PingResult(Reply); } }
private void p_PingCompleted(object sender, PingCompletedEventArgs e) { string ip = (string)e.UserState; Console.WriteLine("scanning {0}", ip); if (e.Reply != null && e.Reply.Status == IPStatus.Success) { /* * string name; * try * { * IPHostEntry hostEntry = Dns.GetHostEntry(ip); * name = hostEntry.HostName; * } * catch (SocketException ex) * { * name = "?"; * } * Console.WriteLine("{0} ({1}) is up: ({2} ms)", ip, name, e.Reply.RoundtripTime); */ string name; try { IPHostEntry hostEntry = Dns.GetHostEntry(ip); name = hostEntry.HostName; } catch (SocketException ex) { name = "name unknown\nException: " + ex; } Console.WriteLine("found one --> {0}", ip); string nameForListbox = "" + ip + "\t(" + name + ")"; lock (lockObj) { upCount++; foundIps.Add(nameForListbox); } } countdown.Signal(); }
void ping_PingCompleted(object sender, PingCompletedEventArgs e) { if (e.Error != null) { listBox1.Items.Add(e.Error.Message); return; } if (e.Cancelled) { listBox1.Items.Add("Przerwano operację na życzenie użytkownika."); } else { if (e.Reply.Status == IPStatus.TtlExpired) { listBox1.Items.Add("Skok " + i.ToString() + " host: " + e.Reply.Address.ToString()); } if (e.Reply.Status == IPStatus.TimedOut) { listBox1.Items.Add("Skok " + i.ToString() + " host: * Upłynął limit czasu żądania."); } if (e.Reply.Status == IPStatus.Success) { listBox1.Items.Add("Skok " + i.ToString() + " host: " + e.Reply.Address.ToString()); return; button1.Enabled = true; } if (i++ < (int)numericUpDown1.Value) { PingOptions opcjePing = new PingOptions(i, true); ping.SendAsync(textBox1.Text, (int)numericUpDown2.Value, bufor, opcjePing, null); } else { listBox1.Items.Add("Przekroczono maksymalną liczbę skoków (parametr TTL = " + numericUpDown1.Value.ToString()); button1.Enabled = true; } } }
//Notified update of node status private void Ping_Complete(object sender, PingCompletedEventArgs k) { PingReply reply = k.Reply; IMachineInfo machine = k.UserState as IMachineInfo; try { if (reply.Status == IPStatus.Success) { machine.Alive = (NodeState.Online); } else { machine.Alive = (NodeState.Offline); } } catch (NullReferenceException e) { machine.Alive = (NodeState.Unknown); } }
public static void PingCompletedCallback(object sender, PingCompletedEventArgs e) { // If the operation was canceled, display a message to the user. if (e.Cancelled) { // Debug.Log("Ping canceled."); // Let the main thread resume. // UserToken is the AutoResetEvent object that the main thread // is waiting for. } // If an error occurred, display the exception to the user. if (e.Error != null) { // Debug.Log("Ping failed:"); Debug.Log(e.Error.ToString()); } Debug.Log("Roundtrip Time: " + e.Reply.RoundtripTime); }
private void EndPingSending(object sender, PingCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { listPingResults.Items.Add("Wystąpił błąd lub przerwano operację."); //error of cancel ((IDisposable)(Ping)sender).Dispose(); return; } PingReply reply = e.Reply; //get reply if (reply.Status == IPStatus.Success) { listPingResults.Items.Add(reply.Address.ToString() + " odpowiedź " + reply.Buffer.Length + " bajtów. Czas odpowiedzi: " + reply.RoundtripTime + " ms TTL: " + reply.Options.Ttl); //insert to listBox } else { listPingResults.Items.Add("Brak odpowiedzi od adresu " + e.Reply.Address + " status: " + reply.Status); ((IDisposable)(Ping)sender).Dispose(); } }
private static void Ping_completed(object s, PingCompletedEventArgs e) { lock (@lock) { instances -= 1; } if (e.Reply.Status == IPStatus.Success) { Console.WriteLine(string.Concat("Active IP: ", e.Reply.Address.ToString())); result += 1; lock (@lock) { addresses.Add(e.Reply.Address); } } else { //Console.WriteLine(String.Concat("Non-active IP: ", e.Reply.Address.ToString())) } }
public void EndPing(object sender, PingCompletedEventArgs e) { if (e.Cancelled || e.Error != null) { listBox1.Items.Add("Operation aborted or wrong address"); ((IDisposable)(Ping)sender).Dispose(); return; } PingReply answer = e.Reply; if (answer.Status == IPStatus.Success) { listBox1.Items.Add("Answer with: " + answer.Address.ToString() + " bajt=" + answer.Buffer.Length + " time=" + answer.RoundtripTime + "ms TTL=" + answer.Options.Ttl); } else { listBox1.Items.Add("Error: " + answer.Address.ToString() + " " + answer.Status.ToString()); } ((IDisposable)(Ping)sender).Dispose(); }