The WEB API call stops working after entering the "pending" keyword

I have a simple web api method that retrieves a list of items from a database. When the method looks like this, it works and the items are displayed in the UI:

[ActionName("GetServices")]
public async Task<IHttpActionResult> GetServices()
{
    var services = dbContext.Service.ToListAsync();
    return Ok(services);
}

      

But as soon as await

I put the keyword in the method, it stops working (if I put a breakpoint on the method that still hits, but nothing is displayed in the UI):

[ActionName("GetServices")]
public async Task<IHttpActionResult> GetServices()
{
    var services = await dbContext.Service.ToListAsync();
    return Ok(services);
}

      

+3


source to share


1 answer


"Waiting" essentially means that you are causing the runtime to wait until this method is executed. The first code snippet returns the task object and the second one returns the actual services from db. Since you are saying that with the first block of code it renders services, you should expect this task object in your custom layer. You must change your UI layer code after you put it in the WEB API.



-1


source







All Articles