Azure/Xamarin移动应用程序挂在SyncContext.InitializeAsync [英] Azure/Xamarin Mobile App Hangs at SyncContext.InitializeAsync

查看:95
本文介绍了Azure/Xamarin移动应用程序挂在SyncContext.InitializeAsync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个运行正常的xamarin表单应用程序,该应用程序使用了Azure移动服务.我升级了服务器端以使用移动应用程序服务,并升级了客户端中的nuget以使用最新和最好的客户端代码.

So, I had a working xamarin forms app that used azure mobile services. I upgraded the server side to use mobile app service and upgraded the nugets in my client to use the latest and greatest client codes.

我手动更新了test/ios模拟器sqlite db,以便为系统属性使用正确的列名,因为它们删除了双下划线前缀.

I manually updated my test/ios simulator sqlite db to use the proper column names for the system properties since they dropped the double underscore prefix.

当我最终将其全部构建并尝试在ios 6/8.3模拟器中运行时,它运行良好,直到遇到InitializeAsync方法为止.它不会抛出(处于尝试状态),我让它运行了很长一段时间,只坐在那里.

When I finally got it all built and tried to run in the ios 6/8.3 simulator it ran fine until it hit the InitializeAsync method. It doesn't throw (its in a try catch) and I let it run for a long time and it just sits there.

然后我尝试更改数据库名称,以便从头开始使用它,但确实仍然挂起.因此,我然后尝试将其简化为一个表,并取出了委托处理程序,使它尽可能基本,并且仍然挂起.

I then tried to change the db name so it would make it from scratch, which it did but still just hung. So I then tried to simplify it to a single table and took out my delegating handler so it was as basic as I could get it and it still just hangs.

还有其他人有这个问题吗?我完全不知所措,因为我没有得到任何错误.不知道从哪里开始.

Has anyone else had this problem? I am at a complete loss because I don't get an error. Not sure where to start.

谢谢.

编辑,添加了代码:

var store = new MobileServiceSQLiteStore(_localDatabaseName);

store.DefineTable<Profile>();
try
{
    await _mobileService.SyncContext.InitializeAsync(store);
}
catch (Exception e)
{
    Debug.WriteLine(e.Message);
}

我也按照建议尝试使用ConfigureAwait(false),但是没有什么区别. 我在catch和此块之后的代码中设置了断点,但它们从未被命中.

I also tried with ConfigureAwait(false) as suggested but it made no difference. I set breakpoints in the catch and the code that immediately follows this block but they are never hit.

推荐答案

好吧,所以我仔细研究了一下,发现了一些关于死锁线程的信息,这些信息由异步/等待的专家Stephen Cleary回答. 它使我转向上游.调用我的蔚蓝初始化代码看起来像这样:

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);
}

并且SyncContext.InitializeAsync()调用工作正常,并继续进行.

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

所以,我真的不知道这个答案,我猜想新的azure客户端的内部功能与旧代码有所不同,因为使用Wait()是我以前做过的事情,并且从未出现过问题.但是存在某种线程死锁.很奇怪,花了几天的时间才能过去,现在我必须修复我遇到的下一个僵局.如果斯蒂芬在那儿并且可以提供一些说明,那将是很好的.

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.

这篇关于Azure/Xamarin移动应用程序挂在SyncContext.InitializeAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆