コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 private static void HandleDownloadComplete(object sender, AsyncCompletedEventArgs eventArgs)
 {
     ThreadsHelper.PulseMonitor(eventArgs);
 }