private async Task LoadProductsAsync() { statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProductsAsync():Start" }); ProductProxyService.ProductServiceClient client = new ProductProxyService.ProductServiceClient(); IList <ProductProxyService.Product> products = await client.GetProductsTaskAsync(); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProductsAsync():End" }); ProductGridView.DataSource = products.Take(10); ProductGridView.DataBind(); ThreadGridView.DataSource = statistics; ThreadGridView.DataBind(); TimeSpan ts = pageWatch.Elapsed; PageElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); }
protected void Page_Load(object sender, EventArgs e) { Stopwatch loadWatch = new Stopwatch(); loadWatch.Start(); pageWatch.Start(); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "Page Load:Start" }); //RegisterAsyncTask(new PageAsyncTask(LoadProductsAsync)); RegisterAsyncTask(new PageAsyncTask(async() => { statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProductsAsync():Start" }); ProductProxyService.ProductServiceClient client = new ProductProxyService.ProductServiceClient(); IList <ProductProxyService.Product> products = await client.GetProductsTaskAsync(); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProductsAsync():End" }); ProductGridView.DataSource = products.Take(10); ProductGridView.DataBind(); ThreadGridView.DataSource = statistics; ThreadGridView.DataBind(); TimeSpan ts1 = pageWatch.Elapsed; PageElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts1.Hours, ts1.Minutes, ts1.Seconds, ts1.Milliseconds / 10); })); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "Page Load::End" }); TimeSpan ts = loadWatch.Elapsed; LoadElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); }
private void LoadProducts() { statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProducts():Start" }); ProductProxyService.ProductServiceClient client = new ProductProxyService.ProductServiceClient(); IList <ProductProxyService.Product> products = client.GetProducts(); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadProducts():End" }); ProductGridView.DataSource = products.Take(10); ProductGridView.DataBind(); }
private async Task LoadAsync() { statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadAsync():Start" }); ProductProxyService.ProductServiceClient client = new ProductProxyService.ProductServiceClient(); SaleOrderProxyService.SaleOrderServiceClient saleOrderClient = new SaleOrderProxyService.SaleOrderServiceClient(); PersonProxyService.PersonServiceClient personClient = new PersonProxyService.PersonServiceClient(); var productsTask = client.GetProductsTaskAsync(); var saleOrdersTask = saleOrderClient.GetSaleOrdersTaskAsync(); var personTask = personClient.GetPersonsTaskAsync(); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadAsync():Before WhenAll()" }); await Task.WhenAll(productsTask, saleOrdersTask, personTask); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadAsync():Tasks all done." }); LoadProducts(productsTask.Result); LoadSaleOrders(saleOrdersTask.Result); LoadPersons(personTask.Result); statistics.Add(new Statistic { ThreadId = Thread.CurrentThread.ManagedThreadId, Message = "LoadAsync():Exit" }); ThreadGridView.DataSource = statistics; ThreadGridView.DataBind(); TimeSpan ts = pageWatch.Elapsed; PageElapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); }