c# - difference between await Task(ReadFromIO) and await Task.WhenAll(task1,task2); -


i read in book differences of below.

private async task getdataasync() { var task1 = readdatafromioasync(); var task2 = readdatafromioasync(); // here can more processing // doesn't need data previous calls. // need data have wait await task.whenall(task1, task2); // have data show. lblresult.content = task1.result; lblresult2.content = task2.result; }  private async task getdataasync() { var task1 = readdatafromioasync(); var task2 = readdatafromioasync(); lblresult.content = await task1; lblresult2.content = await task2; } 

i understood whats happening in first method's await statement. second one, though understood logic couldn't understand pitfall of second implementation compared first. in book, mentioned compiler rewrites method twice. understood because of 2 await calls, there time delay more first 1 separately call await each task here. can explain me in better way?

i don't know point book trying make agree initial guess @ it's interoperation.

potentially issue there period of time lblresult shows new data , lblresult2 shows old data if task2 takes longer task1 process. in first method wait till both tasks finish update both labels @ same time (and when exit method both repainted on screen same time). in second method update first label give message loop opportunity repaint screen time later update 2nd label , have value updated on screen.

i guess have slightly more complex state machine 2nd example overhead of negligible, confident book trying point out issue , both came with.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -