In some article about asynchronous web api 2 actions, I have found following code that shows how to implement async operations in Web Api 2:
public class UserController : ApiController
{
ApiSecurityEntities _db = new ApiSecurityEntities();
public async Task<IHttpActionResult> Delete(Int32 Id)
{
var record = await _db.UserMaster.Where(f => f.id == Id).FirstOrDefaultAsync();
if (record != null)
{
_db.UserMaster.Remove(record);
await _db.SaveChangesAsync();
return Ok();
}
return NotFound();
}
}
I suppose that this code is not async, but it's only wrapped with async/await
words. Can you dispel my doubts?
#EDIT
Reasons why I'm supposing that isn't truly async code:
- After first
await
there is onlyif
statement that must wait for previous operation and no other work will be done after this block, so it will be run synchronously - After second
await
there isreturn
statement, so it must wait until_db.SaveChangesAsync();
will be done