예제 #1
0
        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            TestButton.IsEnabled = false;

            var sb = new StringBuilder();
            StockServiceClient proxy = new StockServiceClient();

            List<Task> tasks = new List<Task>();

            for (int i = 0; i < 5; i++)
            {
                sb.AppendFormat("{0}: Calling GetPrice", System.DateTime.Now);
                sb.AppendLine();

                var task = proxy.GetPriceAsync("MSFT")
                    .ContinueWith(
                        (prevTask) => sb.AppendFormat("{0}: Price:{1}\n", DateTime.Now, prevTask.Result));

                tasks.Add(task);
            }

            await Task.WhenAll(tasks);

            ResTextBox.Text = sb.ToString();

            TestButton.IsEnabled = true;
        }