コード例 #1
0
        private static void Example7PageDownload()
        {
            // this solution still use 2 threads during operation
            var           downloader   = new PageDownloader();
            Task <string> downloadTask = downloader.DownloadWebPageAsync("someurl");

            while (!downloadTask.IsCompleted)
            {
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine(downloadTask.Result);
        }
コード例 #2
0
        private static void Example8BetterPageDownload()
        {
            // this solution take second thread to start operation
            // then put it back to threadpool and after completion of operation
            // takes thread again from thread pool
            var           downloader   = new PageDownloader();
            Task <string> downloadTask = downloader.BetterDownloadWebPageAsync("someurl");

            while (!downloadTask.IsCompleted)
            {
                Console.Write(".");
                Thread.Sleep(250);
            }
            Console.WriteLine(downloadTask.Result);
        }