DEV Community

Discussion on: How C# asynchronous programming is different than what you think

 
yaser profile image
Yaser Al-Najjar

My rule of thumb is:

  • If I want nonblocking code that is related to IO (say talk to db) without creating a thread, I simply throw async/await everywhere.

  • If I want to create a thread to do some cpu heavy computation, I add Task.Run and fill in the lambda my sync code (and for sure that requires adding async/await).

This is the way I do async C#... I should say I never tried to check those statements 😁

Also, some operations might lead the OS to create a thread, but that doesn't count on our app process (it's the way the OS does its business instead).

Thanks for the recommendation, I just read her posts and they seem interesting!