© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
35 replies
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
Parallel.ForEach

Task.WhenAll
Task.WhenAll

and
Task.Run
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
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
Task.WhenAll
?

and if I have a
async Task
async Task
that I don't want to
await
await
as it's loading the notifications panel rather than a page, can I just run that in
Task.Run
Task.Run
? Without awaiting it?
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Micro-optimizing a Z80 emulators' pipeline. **Unsafe code**
C#CC# / help
15mo ago
❔ Optimizing Homescreen API
C#CC# / help
3y ago
❔ Optimizing EF query
C#CC# / help
3y ago