On 20 April 2016 at 17:34, Greg Keogh <[email protected]> wrote:
> Folks, I want to make the parallel calls to a web service that can take 2 to
> 5 seconds. It's like this now:
>
> Task t1 = GetStuffAsync("Key1");
> Task t2 = GetStuffAsync("Key2");
> Task t2 = GetStuffAsync("Key3");
> await t1; await t2; await t3;
> UpdateUI(t1.Result);
> UpdateUI(t2.Result);
> UpdateUI(t3.Result);
>
> This runs the GetStuffs in parallel, but the UI doesn't update until all 3
> finish. What's the best way of rejigging this so that each get-and-update
> runs in parallel?

On 20 April 2016 at 17:53, Thomas Koster <[email protected]> wrote:
> Coding off-hand, is this what you had in mind?
>
> async Task GetStuffAndUpdateUI(string key)
> {
>     var r = await GetStuffAsync(key);
>     UpdateUI(r);
> }
>
> GetStuffAndUpdateUI("Key1");
> GetStuffAndUpdateUI("Key2");
> GetStuffAndUpdateUI("Key3");

Sorry, GetStuffAndUpdateUI should have been called GetStuffAndUpdateUIAsync.

--
Thomas Koster

Reply via email to