C#C
C#3y ago
Shemiroth

❔ Optimizing code

Currently I am refactoring some code in my WPF app as some parts load quite slow. I am wondering what is the correct way to use stuff like

Parallel.ForEach
Task.WhenAll
and
Task.Run

For example I have a for loop that iterates through a collection and makes an API call for each, they are not really dependent on each other. So is that a good case for Parallel.ForEach? (ignoring the fact that I need to optimize by making a single API call 😅 )

Then I have some initialization methods on my ViewModels that gather data with a few API calls. Like one to get personnel and another to get app data like settings. Is that a good case for Task.WhenAll?

and if I have a async Task that I don't want to await as it's loading the notifications panel rather than a page, can I just run that in Task.Run? Without awaiting it?
image.png
Was this page helpful?