entity framework - How to avoid async/await deadlock when blocking is required -


i have following issue singleordefaultasync ef not complete.

i added 2 calls evaluating a , b both returns correct value. test line never completing , method waits ever.

anyone experienced similar or have hints on can cause this.

        public async task<subscription> findsubscriptionbyidasync(guid subscriptionid)         {             //works             var = dbcontext.subscriptions.singleordefault(x => x.id == subscriptionid);             //works             var b = dbcontext.subscriptions.include(s => s.storagelocations).singleordefault(x => x.id == subscriptionid);              //no exceptions or anyhting, not continue              var test =await dbcontext.subscriptions                 .include(s => s.storagelocations)                 .singleordefaultasync(x => x.id == subscriptionid);             //debugger never gets point.             return test;          } 

update

based on answer/comments know root issue is:

    public override cloudstorageaccount getstorageaccount(string tenant, string purpose = null)     {         return getstorageaccountasync(new guid(tenant), purpose).getawaiter().getresult();     } 

and problem getstorageaccount implemented above because of interface such not option return task.

since own interface have updated interface return task though, if not update design , forced return none task version of object? proper way of executing getstorageaccountasync() out doing deadlock?

this classic asp.net await deadlock. have been calling wait or result somewhere. don't that.

if must block (which have indicated) block in safe way: task.run(anything).result. don't modify sites await. if miss 1 deadlock (potentially non-deterministically @ 4am in night in production).

in example code be:

task.run(() => getstorageaccountasync(new guid(tenant), purpose)).result 

which safe.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -