Getting synchronous behavior from ToListAsync
Posted: Thu 30 Jul 2015 15:06
Hi,
I have code in my application that uses DevArt dotConnect (version 8.4.457) to connect to an oracle 12c database. I have code that looks like this:
using (var context = new MyContext(myConnectionString)
{
var data = (some lync query).ToListAsync();
var data2 = (some lync query).ToListAsync();
etc etc....
await Task.WhenAll(new Task[] {data, data2....});
}
I have 6 somewhat long running queries (~2 seconds each) that I'm trying to execute in parallel. However this does not appear to be happening. When I run in the debugger and step through the ToListAsync, there is a noticeable pause after each ToListAsync() line like the query is actually running (I can't confirm because I don't have access to trace on the DB and these queries apparently don't show up in intellisense like others do). I would expect the first query to take a second or so to build the EF model, but the other ToListAsync() calls should return immediately. Plus, if I put a breakpoint at the await line, the tasks are ALWAYS completed. Further, according to documentation I read while researching this, the above code shouldn't even work when there are multiple async calls within a dbcontext scope because dbconext isn't threadsafe, so that further suggests that there really isn't anything async happening here.
Please confirm that ToListAsync (and other async methods) truely execute asynchronously, and if so, please advise on what is wrong here.
I have code in my application that uses DevArt dotConnect (version 8.4.457) to connect to an oracle 12c database. I have code that looks like this:
using (var context = new MyContext(myConnectionString)
{
var data = (some lync query).ToListAsync();
var data2 = (some lync query).ToListAsync();
etc etc....
await Task.WhenAll(new Task[] {data, data2....});
}
I have 6 somewhat long running queries (~2 seconds each) that I'm trying to execute in parallel. However this does not appear to be happening. When I run in the debugger and step through the ToListAsync, there is a noticeable pause after each ToListAsync() line like the query is actually running (I can't confirm because I don't have access to trace on the DB and these queries apparently don't show up in intellisense like others do). I would expect the first query to take a second or so to build the EF model, but the other ToListAsync() calls should return immediately. Plus, if I put a breakpoint at the await line, the tasks are ALWAYS completed. Further, according to documentation I read while researching this, the above code shouldn't even work when there are multiple async calls within a dbcontext scope because dbconext isn't threadsafe, so that further suggests that there really isn't anything async happening here.
Please confirm that ToListAsync (and other async methods) truely execute asynchronously, and if so, please advise on what is wrong here.