Example #1
0
        private void UpdatePingForm(PingData pingData)
        {
            notifyIcon.Icon = GetIcon(pingData.Status == IPStatus.Success ? pingData.Time : 0);
            if (pingData.Address != null)
            {
                string[] ipParts = pingData.Address.ToString().Split('.');
                if (ipParts.Length == 4)
                {
                    txtIP1.Text = int.Parse(ipParts[0]).ToString("000");
                    txtIP2.Text = int.Parse(ipParts[1]).ToString("000");
                    txtIP3.Text = int.Parse(ipParts[2]).ToString("000");
                    txtIP4.Text = int.Parse(ipParts[3]).ToString("000");
                }
                txtTTL.Text = pingData.TTL.ToString();
            }
            if (notifyIcon.Visible && pingData.Status != IPStatus.Success)
            {
                notifyIcon.BalloonTipIcon  = ToolTipIcon.Warning;
                notifyIcon.BalloonTipTitle = Text;
                notifyIcon.BalloonTipText  = "Ping error:" + Environment.NewLine + pingData.Message;
                notifyIcon.ShowBalloonTip(1000);
            }
            var lableText = pingData.Status == IPStatus.Success ? pingData.Time + " ms" : pingData.Status.ToString();

            notifyIcon.Text   = Text = string.Format(_titleTemplate, lableText);
            lblPing.Text      = lableText;
            lblPing.BackColor = pingData.Color;
            Logger.Log(pingData.TimeStamp, pingData.ToString(), pingData.Color, pingData.Status != IPStatus.Success || pingData.Time >= nudLog.Value);
            TaskBarProgress.SetProgressState(Handle, GetProgressState(pingData.Status == IPStatus.Success ? pingData.Time : 0));
            TaskBarProgress.SetProgressValue(Handle, 100, 100);
        }
Example #2
0
        private void pingWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var pingData = e.UserState as PingData;

            if (pingData != null)
            {
                UpdatePingForm(pingData);
            }
            else
            {
                var s   = e.UserState as PingSettings;
                var avg = s.Attempts > 0 ? s.PingTotal / s.Attempts : 0;
                Logger.Log(null, "Avg ping: " + avg + " ms.", Color.DeepPink, true);
                Logger.Log(null, "Stop ping host '" + s.HostName + "'.", null, true);
                lblPing.Text      = s.Attempts > 0 ? avg + " ms" : "n/a";
                lblPing.BackColor = PingData.GetColor(s.Attempts > 0 ? (long)avg : -1);
            }
        }