Hi Greg,

On 20 April 2016 at 17:34, Greg Keogh <gfke...@gmail.com> 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?

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");

--
Thomas

Reply via email to