Stored procedure asynchronous

1

When attempting to execute procedure asynchronously

public async Task<ActionResult> Index()
    {
        Stopwatch watch = new Stopwatch();
        watch.Start();
        ContentManagement service = new ContentManagement();
        var contentTask = service.MesesAsync();
        var content = await contentTask;
        watch.Stop();                    
        ViewBag.WatchMilliseconds = watch.ElapsedMilliseconds;
        return View("Index");
     }

public async Task<List<SP_MESES_BUSCA_Result>> MesesAsync()
    {
        var ListarMes = await db.SP_MESES_BUSCA().ToList();
        return ListarMes;
    }

Returns the error:

  

Can not await 'System.Collections.Generic.List'

    
asked by anonymous 14.06.2016 / 20:25

1 answer

2

The await in your MesesAsync() method is waiting for an asynchronous statement.

Just change the ToList() to ToListAsync() that will work.

Your code will look like this;

public async Task<List<SP_MESES_BUSCA_Result>> MesesAsync()
    {
        var ListarMes = await db.SP_MESES_BUSCA().ToListAsync();
        return ListarMes;
    }
    
14.06.2016 / 20:41