C # Why is Task WhenAll blocking the UI thread? but doesn't wait on every line?

When I run this code, there are no blocks, everything is fine and dandy:

    List<Category> cats = null;
    cats = await cat.GetAllAsync();//no blocks here
    cats = await cat.GetAllAsync();//no blocks here
    cats = await cat.GetAllAsync();//no blocks here
    cats = await cat.GetAllAsync();//no blocks here
    cats = await cat.GetAllAsync();//no blocks here

      

But this other code does, and I don't understand why, I appreciate your help,

    var tasks = new List<Task>();
    tasks.Add(cat.GetAllAsync());
    tasks.Add(cat.GetAllAsync());
    tasks.Add(cat.GetAllAsync());
    tasks.Add(cat.GetAllAsync());
    tasks.Add(cat.GetAllAsync());
    await Task.WhenAll(tasks); //this blocks the UI thread

      

EDIT: I figured GetAllAsync sproc asynchronously, but then creates a list of categories from the returned DataSet, but there is no asynchronization there, so the main thread picks that up and links one hundred thousand categories! which is blocking the UI! DOH!

thanks for the help,

+3


source to share


1 answer


Is cat.GetAllAsync re-entrant \ thread safe? In the first example, multiple calls to cat.GetAllAsync are run in sequence. In the second example, potentially multiple calls to cat.GetAllAsync can be done in parallel, I assume it is causing blocking \ deadlock inside cat.GetAllAsync



+4


source







All Articles