Beispiel #1
0
        private async void SendPing(string ip)
        {
            btPing.Enabled = false;
            btPing.Text    = "Pinging...";
            var resp = await Pinger.PingHost(currentAddress.ToStringWithoutMask());

            btPing.Enabled = true;
            btPing.Text    = "Ping";
            MessageBox.Show(resp);
        }
Beispiel #2
0
            public MyCustomApplicationContext()
            {
                targetIp = File.ReadAllText("ip.conf");

                pinger = new Pinger();

                trayIcon = new NotifyIcon()
                {
                    Icon        = Resources.Trayicon,
                    ContextMenu = new ContextMenu(new MenuItem[] {
                        new MenuItem("Прекратить проверку", Exit)
                    }),
                    Visible = true,
                    Text    = "Проверщик телефона на подключенность к WiFi"
                };

                trayIcon.Click += (s, o) =>
                {
                    trayIcon.ShowBalloonTip(10000, "Последний раз телефон был доступен", LastPinged.ToString(), ToolTipIcon.Info);
                };

                timer = new Timer
                {
                    Enabled  = true,
                    Interval = 2500
                };
                timer.Tick += (s, o) =>
                {
                    if (pinger.PingHost(targetIp))
                    {
                        FailedAttempts = 0;
                        LastPinged     = DateTime.Now;
                    }
                    else
                    {
                        FailedAttempts++;
                    }

                    if (FailedAttempts > 5)
                    {
                        FailedAttempts = 0;
                        trayIcon.ShowBalloonTip(10000, "Проверщик телефона", "Не могу найти телефон.\r\nОн отключен?", ToolTipIcon.Warning);
                    }
                };
            }