private void ReportProgress(object sender, ProgressBarModel e)
 {
     progressbar.Value = e.ProgressPercentage;
     DisplayContentInListBox(new List <string> {
         e.ProgressMesssage
     });
 }
Exemplo n.º 2
0
        public async Task <List <string> > GetWebsiteContentLengthAsync(IProgress <ProgressBarModel> progress, CancellationToken token)
        {
            var websites = GetWebsites();

            List <string>    websiteContents = new List <string>();
            ProgressBarModel progressModel   = new ProgressBarModel();

            foreach (var site in websites)
            {
                token.ThrowIfCancellationRequested();
                var content = await DownloadDataAsync(site);

                websiteContents.Add(content);
                progressModel.ProgressPercentage = (websiteContents.Count * 100) / websites.Count;
                progressModel.ProgressMesssage   = $"Processing Files {site}";
                progress.Report(progressModel);
            }
            return(websiteContents);
        }
Exemplo n.º 3
0
        public async Task <List <string> > GetWebsiteContentLengthParallelAsync_V2(IProgress <ProgressBarModel> progress, CancellationToken token)
        {
            var              websites        = GetWebsites();
            List <string>    websiteContents = new List <string>();
            ProgressBarModel progressModel   = new ProgressBarModel();

            await Task.Run(() =>
            {
                Parallel.ForEach <string>(websites, (site) =>
                {
                    token.ThrowIfCancellationRequested();
                    var content = DownloadDataSync(site);
                    websiteContents.Add(content);
                    progressModel.ProgressPercentage = (websiteContents.Count * 100) / websites.Count;
                    progressModel.ProgressMesssage   = $"Processing Files {site}";
                    progress.Report(progressModel);
                });
            });

            return(websiteContents);
        }