예제 #1
0
        private void RunDownloadSync()
        {
            List <string> websites = PrepData();

            foreach (var site in websites)
            {
                WebsiteDataModel results = DownloadWebsite(site);
                ReportWebsiteInfo(results);
            }
        }
예제 #2
0
        private async Task <WebsiteDataModel> DownloadWebsiteAsync(string websiteUrl)
        {
            var       model  = new WebsiteDataModel();
            WebClient client = new WebClient();

            model.WebsiteUrl  = websiteUrl;
            model.WebsiteData = await client.DownloadStringTaskAsync(websiteUrl);

            return(model);
        }
예제 #3
0
        private WebsiteDataModel DownloadWebsite(string websiteUrl)
        {
            var       model  = new WebsiteDataModel();
            WebClient client = new WebClient();

            model.WebsiteUrl  = websiteUrl;
            model.WebsiteData = client.DownloadString(websiteUrl);

            return(model);
        }
예제 #4
0
        private async Task RunDownloadASync()
        {
            List <string> websites = PrepData();

            foreach (var site in websites)
            {
                //Task.Run() is used to wrap around code that you want to run asynchronous.
                //The await keyword tells the code to run the task asynchronously but wait for the result.
                //The point to do this is to let the let the UI-thread do its other jobs while a new thread takes care of the DownloadWebsite operation.
                WebsiteDataModel results = await Task.Run(() => DownloadWebsite(site));

                ReportWebsiteInfo(results);
            }
        }
예제 #5
0
 private void ReportWebsiteInfo(WebsiteDataModel model)
 {
     resultsWindow.Text += $"{model.WebsiteUrl} downloaded: {model.WebsiteData.Length} characters long. {Environment.NewLine}";
 }