Optimize IsConnectedToInternet

Previous implementation visited the site, now it only pings.
pull/32/head
Miepee 4 years ago
parent 7d40116fd2
commit 416c17ecad

@ -2,6 +2,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.NetworkInformation;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace AM2RLauncherLib; namespace AM2RLauncherLib;
@ -141,18 +142,14 @@ public static class HelperMethods
} }
/// <summary> /// <summary>
/// Checks if we currently have an internet connection, by pinging github. /// Checks if we currently have an internet connection, by pinging GitHub.
/// </summary> /// </summary>
/// <returns><see langword="true"/> if we have internet, <see langword="false"/> if not.</returns> /// <returns><see langword="true"/> if we have internet, <see langword="false"/> if not.</returns>
public static bool IsConnectedToInternet() public static bool IsConnectedToInternet()
{ {
log.Info("Checking internet connection..."); log.Info("Checking internet connection...");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://github.com"); PingReply pingReply = new Ping().Send("https://github.com");
try if (pingReply?.Status != IPStatus.Success)
{
request.GetResponse();
}
catch (WebException)
{ {
log.Info("Internet connection failed."); log.Info("Internet connection failed.");
return false; return false;

Loading…
Cancel
Save