-1

In .Net, what happens if you have a Task Controller method with no async await for any of it's operations and the operations of it's dependencies (such as the service classes which are also Task methods not containing async await).

For example, RoomController.cs:

[HttpGet]
public Task<List<Room>> GetRooms()
{
    return _roomService.GetRoomsAsync();
}

... RoomService.cs:

    public Task<List<Room>> GetRoomsAsync()
    {
        return _context.Rooms.ToListAsync();
    }

Can this cause problems or disadvantages?

goamn
  • 1,939
  • 2
  • 23
  • 39
  • 1
    Can you show with a sample what you mean by "with no async await"? – Fabio Oct 15 '19 at 02:34
  • Done, no async in the method declaration and no await for the asynchronous calls – goamn Oct 15 '19 at 04:18
  • No, this approach will not cause problems. There will be a middleware code which will await for controller action Task to complete. – Fabio Oct 15 '19 at 04:42

1 Answers1

0

With using Async await operation in web-API methods, your current thread doesn't wait for an I/O operation: as an example in your code :

 return _context.Rooms.ToListAsync();

this code has an I/O operation to the database, using async-await cause to your current thread could respond to another request and doesn't block to I/O. Consequently, throughput in your application will be increased without using any multithreading technique. This is very beneficial, doesn't it!?