When I run this code, there are no blocks, all 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 get 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 have realized that the GetAllAsync executes the sproc asynchronously but then it creates a list of Categories from the DataSet it returns, but there is no async there, so the main thread picks that up and binds one hundred thousand categories! which blocks the UI! doh!
thanks for the help,
Is cat.GetAllAsync re-entrant\thread safe? In your first example multiple calls to cat.GetAllAsync are run sequentially. In your second example potentially multiple calls to cat.GetAllAsync can run in parallel, my guess is that it causes a lock\deadlock inside cat.GetAllAsync
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With