Azure/Xamarin Mobile App Hangs at SyncContext.InitializeAsync

老子叫甜甜 提交于 2019-12-04 16:04:41

Ok, so I poked around a bit more and found some info on deadlocked threads answered by Stephen Cleary, the guru of async/await. It turned me onto looking upstream. The call into my azure init code looked like this:

var azureService = Container.Get<IAzureService>();
azureService.InitializeAzync().Wait();

Which was in the constructor of the calling component. So, I changed it to this:

try
{
    Task.Run(() => azureService.InitializeAsync()).Wait();
}
catch (Exception ex)
{
    Debug.WriteLine(ex.Message);
}

And the SyncContext.InitializeAsync() call worked fine and continued on.

So, I don't really know the answer for this, I guess the internals of the new azure client do something differently than the old code since using Wait() was how I did it before and never had a problem. But there was some sort of threading deadlock. Very odd and took days to get past, now I have to fix the next deadlock I hit. If Stephen is out there and can offer some clarification that would be great.

Had this same issue - changing to a Task.Run and ConfigureAwait(false) did fix it.

Very odd thing is the same code worked fine with Mobile Services, but broke when we upgraded to Mobile App Services.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!