public static void WaitForDecentInternetConnection(double minimumInternetSpeed, int goodPings, int minimumGoodPings, int waitingTime) { while (true) { if (goodPings >= 0) { double myConnectionSpeed; do { myConnectionSpeed = CheckInternetSpeed(); if (!(myConnectionSpeed < minimumInternetSpeed)) { continue; } goodPings = minimumGoodPings; NotificationsHelper.DisplayDynamicMessage(Messages.WaitForBetterInternet(myConnectionSpeed)); ThreadsHelper.Sleep(waitingTime); } while (myConnectionSpeed < minimumInternetSpeed); goodPings--; continue; } break; } }
public static bool DownloadFile(string url, string downloadDirectory) { try { var filePath = PathsHelper.CreatePath(url, downloadDirectory); WebClient.DownloadProgressChanged += HandleDownloadProgress; WebClient.DownloadFileCompleted += HandleDownloadComplete; var syncObject = new object(); lock (syncObject) { WebClient.DownloadFileAsync(new Uri(url), filePath, syncObject); ThreadsHelper.MonitorWait(syncObject); } return(true); } catch { return(false); } }
private static void HandleDownloadComplete(object sender, AsyncCompletedEventArgs eventArgs) { ThreadsHelper.PulseMonitor(eventArgs); }