Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'apress dot net test automation recipes_2', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 5 PARALLELIZATION AND THREADING ENHANCEMENTS factorials or walk trees of data but I think this distracts at least initially from understanding the basics. If you want to work with a more realistic example take a look at the examples from the parallel team you will find excellent ray tracing and other math related examples. Note that calling the Thread.Sleep method will involve a context switch an expensive operation for the CPU so it might slow the sample application down more than performing work might have. 1. Create a new console application called Chapter5.HelloParalleland add the following using directives using System.Diagnostics using System.Threading.Tasks 2. Amend Program.cs to the following code class Program . . public static List StockQuote Stocks new List StockQuote static void Main string args . double serialSeconds 0 double parallelSeconds 0 Stopwatch sw new Stopwatch PopulateStockList sw Stopwatch.StartNew RunInSerial serialSeconds sw.Elapsed.TotalSeconds sw Stopwatch.StartNew RunInParallel parallelSeconds sw.Elapsed.TotalSeconds Console.WriteLine Finished serial at 0 and took 1 DateTime.Now serialSeconds Console.WriteLine Finished parallel at 0 and took 1 DateTime.Now parallelSeconds Console.ReadLine private static void PopulateStockList Stocks.Add new StockQuote ID 1 Stocks.Add new StockQuote ID 2 Stocks.Add new StockQuote ID 3 Stocks.Add new StockQuote ID 4 Stocks.Add new StockQuote ID 5 Stocks.Add new StockQuote ID 6 Company Microsoft Price 5.34m Company IBM Price 1.9m Company Yahoo Price 2.34m Company Google Price 1.54m Company Altavista Price 4.74m Company Ask Price 3.21m 102 CHAPTER 5 PARALLELIZATION AND THREADING ENHANCEMENTS Stocks.Add new StockQuote ID 7 Company Amazon Price 20.8m Stocks.Add new StockQuote ID 8 Company HSBC Price 54.6m Stocks.Add new StockQuote ID 9 Company Barclays Price 23.2m Stocks.Add new StockQuote ID 10 Company Gilette Price 1.84m private static void RunInSerial for int i 0 i Stocks.Count i 7 . . .