C#C
C#8mo ago
aetherclouds

Why use `await AbcAsync()` instead of `Abc()`

I'm going through the tutorial in this page: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/controller-methods-views?view=aspnetcore-9.0
I don't understand this bit of generated code inside an async controller method:
// . . .
_context.Update(movie);
await _context.SaveChangesAsync();
// . . .

why call _context.SaveChangesAsync() and then immediately await it, instead of the synchronous version _context.SaveChanges() (which does exist)?

I assume that this is because the async method will only temporarily free the thread to do other work once it hits an await, but that doesn't make sense, because that's the whole point of an async method (whether it uses await inside its body or not).
Part 6, add a model to an ASP.NET Core MVC app
Was this page helpful?