IsInternetConnected() public static method

Checks whether an internet connection is available.
public static IsInternetConnected ( bool fast = true ) : bool
fast bool
return bool
Example #1
0
        public Dialog()
        {
            while (!Util.IsInternetConnected())
            {
                Thread.Sleep(TimeSpan.FromMinutes(5));
            }
            Util.CheckInitRegistry();

            InitializeComponent();
            IconOld   = notifyIcon.Icon;
            soundPath = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location) + @"\Notify.wav";
            if (!File.Exists(soundPath))
            {
                soundPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows) +
                            @"\Media\Windows Notify.wav";
            }
            Location = new Point(
                Screen.PrimaryScreen.WorkingArea.Width - Width,
                Screen.PrimaryScreen.WorkingArea.Height - Height);
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(OnNetworkAvailabilityChanged);
            SystemEvents.PowerModeChanged            += new PowerModeChangedEventHandler(OnPowerModeChanged);
            Imap.NewMessageEvent += new NewMessageEventHandler(OnNewMessage);

            var login = Environment.UserName + "@oblpro.ru";

            if (!(new Regex(@"\w+_\w{2}@oblpro\.ru").IsMatch(login)))
            {
                DisplayOkno();
                Environment.Exit(0);
            }

            var password = Util.GetPassword() ?? PromptPassword(login);

            Util.DeletePassword();
            while (!Imap.VerifyCredentials(login, password))
            {
                password = PromptPassword(login);
            }
            Util.SavePassword(password);
            Imap.SetCredentials(login, password);
            Imap.Start();
            CheckNewMail();
            timer.Enabled = true;
        }
Example #2
0
 private void timer_Tick(object sender, EventArgs e)
 {
     if (Util.IsInternetConnected())
     {
         if (Imap.Started())
         {
             UpdateTrayIcon(Imap.GetUnreadCount());
         }
         else
         {
             /* attempt to silently reconnect */
             Reconnect(false);
         }
     }
     else
     {
         /* Stop if not connected to the internet */
         Imap.Stop();
     }
 }