private async void AllThreeBtn_Click(object sender, RoutedEventArgs e)
        {
            var cts = new CancellationTokenSource(TimeSpan.FromMinutes(CTS_TIMEOUT_DEFAULT));
            var ct  = cts.Token;

            this.UKCountiesList1.ItemsSource = new string[] { "...Loading..." };
            this.UKCountiesList2.ItemsSource = new string[] { "...Loading..." };
            this.UKCountiesList3.ItemsSource = new string[] { "...Loading..." };

            var taskA = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties?delay=3s", ct, captureContext: false);
            var taskB = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties?delay=5s", ct, captureContext: false);
            var taskC = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties", ct, captureContext: false);

            Task <IEnumerable <UKCounty> >[] tasks = new [] { taskA, taskB, taskC };

            var tasksMap = new Dictionary <int, ListView>();

            tasksMap.Add(taskA.Id, UKCountiesList1);
            tasksMap.Add(taskB.Id, UKCountiesList2);
            tasksMap.Add(taskC.Id, UKCountiesList3);

            foreach (var t in tasks)
            {
                var res = await t;
                tasksMap[t.Id].ItemsSource = res;
            }
        }
        private async void AllThreeBtnAnyOrder_Click(object sender, RoutedEventArgs e)
        {
            var cts = new CancellationTokenSource(TimeSpan.FromMinutes(CTS_TIMEOUT_DEFAULT));
            var ct  = cts.Token;

            this.UKCountiesList1.ItemsSource = new string[] { "...Loading..." };
            this.UKCountiesList2.ItemsSource = new string[] { "...Loading..." };
            this.UKCountiesList3.ItemsSource = new string[] { "...Loading..." };

            var taskA = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties?delay=3s", ct, captureContext: false);
            var taskB = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties?delay=5s", ct, captureContext: false);
            var taskC = UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties", ct, captureContext: false);

            Task <IEnumerable <UKCounty> >[] tasks = new[] { taskA, taskB, taskC };

            var tasksMap = new Dictionary <int, ListView>();

            tasksMap.Add(taskA.Id, UKCountiesList1);
            tasksMap.Add(taskB.Id, UKCountiesList2);
            tasksMap.Add(taskC.Id, UKCountiesList3);

            async Task AwaitAndProcessAsync(Task <IEnumerable <UKCounty> > t)
            {
                var res = await t;

                tasksMap[t.Id].ItemsSource = res;
            }

            var query = tasks.Select(t => AwaitAndProcessAsync(t));

            Task[] processingTasks = query.ToArray();

            await Task.WhenAll(processingTasks);
        }
Exemplo n.º 3
0
        private async void UKCountiesBtn_Click(object sender, RoutedEventArgs e)
        {
            var cts = new CancellationTokenSource(TimeSpan.FromMinutes(CTS_TIMEOUT_DEFAULT));
            var ct  = cts.Token;

            this.UKCountiesList.ItemsSource = new string[] { "...loading..." };
            var data = await UKCountiesService.GetCountiesAsync($"{App.API_BASE_URL}/ukcounties?delay=3s", ct, captureContext : false);

            this.UKCountiesList.ItemsSource = data;
        }