示例#1
0
        public void RunDownloadSync()
        {
            List <string> websites = Ultility.PrepData();

            foreach (var site in websites)
            {
                WebsiteDataModel result = Ultility.DownloadWebsite(site);
                result.Report();
            }
        }
        public string RunDownloadSync()
        {
            List <string> websites = Ultility.PrepData();

            foreach (var site in websites)
            {
                WebsiteDataModel result = Ultility.DownloadWebsite(site);
                result.Report();
            }
            return($"RunDownloadSync - Done - Thread {Thread.CurrentThread.ManagedThreadId}");
        }
示例#3
0
        public string RunDownload()
        {
            List <string> websites = Ultility.PrepData();

            foreach (var site in websites)
            {
                WebsiteDataModel result = new WebsiteDataModel();
                Thread           thread = new Thread(() => { result = Ultility.DownloadWebsite(site); });
                thread.Start();
                //thread.Join();
                result.Report();
            }
            return($"RunDownloadSync - Done - Thread {Thread.CurrentThread.ManagedThreadId}");
        }
示例#4
0
        public async Task <string> RunDownloadParallelAsync()
        {
            List <string> websites = Ultility.PrepData();
            List <Task <WebsiteDataModel> > tasks = new List <Task <WebsiteDataModel> >();

            for (int i = 0; i < websites.Count; i++)
            {
                var site = websites[i];
                tasks.Add(Task.Run(() => Ultility.DownloadWebsiteAsync(site)));
            }

            var results = await Task.WhenAll(tasks);

            // create a task that completed when all parameter tasks was completed

            foreach (var item in results)
            {
                item.Report();
            }
            return($"RunDownloadParallelAsync - Done - Thread {Thread.CurrentThread.ManagedThreadId}");
        }