0

C# web scaffolding has an async call for every member. Why?

For example: Async for a login call makes no sense. User has to wait for validation. What else would the app do until the application validated the user.

Thoughts?

3
  • Possibly the user may want to cancel the login process? If done synchronously then the app cannot take further input until the login request has been handled to its conclusion. It may be an unlikely event (unless the login request can potentially take a significant period of time to return) but then the asynchrony may be used just for programming consistency rather than functionality. – Steve May 28 '19 at 21:43
  • For web application, client have nothing to do with server side async-await. Response will be returned only when method(login) will be complete – Fabio May 28 '19 at 23:48
  • "What else would the app do until the application validated the user." Serve a request from another user. If you only have one user, then a web app may not be your best solution. If you have multiple users, they don't want to have to wait whilst the server completes a synchronous handling of just one request before moving on to the next. So everything is asynchronous. – David Arno May 29 '19 at 12:25
4

The purpose of async is not to return a value immediately; it is to allow your code to work on something else while your method awaits a return value.

async doesn't magically make your method run faster. It still has to compute a result. What async does do is make your code non-blocking on the server, and it can often do it without spinning up additional threads, because it merely reorders your code while respecting the order of return values.

To find out more about how this process works, read this MSDN article.

2
  • By the way, doesn't async, by its wait for this value nature impose, when working with interfaces, an animation or message about the fact that it's working? I found that designing around it often makes me think a lot more about my interface than I should. Is this an innate thing to async or a byproduct of good standards? – coolpasta May 29 '19 at 1:12
  • @coolpasta: The Task<T> interface that async works with has a Status member that includes IsCanceled, IsCompleted and IsFaulted properties. – Robert Harvey May 29 '19 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.