private void cmdTestAddress_Click(object sender, EventArgs e) { HttpPingEntry tmpHttpPingEntry = new HttpPingEntry(); if (!(txtAddress.Text.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase) || txtAddress.Text.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase))) { txtAddress.Text = "http://" + txtAddress.Text; } tmpHttpPingEntry.Url = txtAddress.Text; tmpHttpPingEntry.ProxyServer = txtProxyServer.Text; tmpHttpPingEntry.MaxTime = (int)nudExpextedTime.Value; tmpHttpPingEntry.TimeOut = (int)nudTimeOut.Value; try { int pingTime = tmpHttpPingEntry.Ping(); if (pingTime == int.MaxValue) { throw new Exception("An error occured while trying to ping the URL\r\n" + tmpHttpPingEntry.LastError); } MessageBox.Show(string.Format("Test success!\r\nTime: {0}ms", pingTime), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RefreshList() { System.Windows.Forms.Cursor.Current = Cursors.WaitCursor; lvwHosts.BeginUpdate(); foreach (ListViewItem itmX in lvwHosts.Items) { HttpPingEntry httpPingEntry = (HttpPingEntry)itmX.Tag; try { int pingTime = httpPingEntry.Ping(); itmX.SubItems[1].Text = pingTime.ToString(); if (pingTime > httpPingEntry.TimeOut) { itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; itmX.SubItems[1].Text = "Time-out"; } else if (pingTime > httpPingEntry.MaxTime) { itmX.ImageIndex = 1; itmX.BackColor = Color.SandyBrown; } else { itmX.ImageIndex = 0; itmX.BackColor = SystemColors.Window; } } catch (Exception ex) { itmX.SubItems[1].Text = ex.Message; itmX.ImageIndex = 2; itmX.BackColor = Color.Salmon; } } lvwHosts.EndUpdate(); System.Windows.Forms.Cursor.Current = Cursors.Default; toolStripStatusLabel1.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); }