0

Does it make sense to make the controller asynchronous if I don't have asynchronous calls in my code. As far as I understand this is an antipattern, the thread has already been allocated from the pool, and since there is no asynchronous code, the asynchronous controller will only be a minus?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Web FR
  • 27
  • 4
  • https://stackoverflow.com/questions/30566848/when-should-i-use-async-controllers-in-asp-net-mvc – Yogi Aug 22 '23 at 03:50
  • Well it's not suggested https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/async-scenarios#important-info-and-advice – Qiang Fu Aug 22 '23 at 06:50

1 Answers1

1

You are correct. More generically, there is no reason to make a method async if it never uses await.

This is not related to it running on a thread pool thread, just that async enables usage of await and requires that the method returns a Task/Task<T>/void. But if you don't await anything, you just end up wrapping your result in a Task for no reason.

juunas
  • 54,244
  • 13
  • 113
  • 149