1
await Task.WhenAll(existingServiceTask, cartServiceTask).ConfigureAwait(false);
var existingService = existingServiceTask.Result; //Is this ok? Any deawback of this?
var carInfo = await cartServiceTask;              //Or this is better?

Try to understand after await WhenAll, if .Result is fine or has any drawbacks?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Som
  • 13
  • 2
  • And some user here in SO adivses [not to await twice](https://blog.marcgravell.com/2019/08/prefer-valuetask-to-task-always-and.html) – Pac0 May 18 '20 at 18:45
  • I'd recommend simply to store the result of `await WaitAll`, though – Pac0 May 18 '20 at 18:46
  • 1
    Does this answer your question? [Get result from Task.WhenAll](https://stackoverflow.com/questions/31554080/get-result-from-task-whenall) – Pac0 May 18 '20 at 18:47
  • 1
    @Pac0 that *is* referring to the difference between `Task` and `ValueTask`, but yes: it is a bad practice to get into – Marc Gravell May 18 '20 at 18:47
  • @MarcGravell Ah, thanks for clarifying this to me, author :) – Pac0 May 18 '20 at 18:48

1 Answers1

1

The best way to do this is as follows.

await Task.WhenAll(existingServiceTask, cartServiceTask).ConfigureAwait(false);
var existingService = await existingServiceTask;
var carInfo = await cartServiceTask; 

Using await will protect you if you forget to put this task in Task.WhenAll

Sergey Solianyk
  • 351
  • 2
  • 10