使用带有Node.js后端的Azure移动应用程序。我把一切都搞定了,有点儿。设置离线同步后,大约需要8分钟才能同步30秒。 调试应用程序后,我发现客户端的一切都很好用。查看网站上的日志,我看到反复运行的“读取脚本”。它每秒都会运行读取脚本,直到它最终完成。
预计会出现这种情况吗?
在等待LocalCards.PullAsync
时挂起在SyncAsync()中阅读脚本
var table = module.exports = require('azure-mobile-apps').table();
table.read(function (context)
{
console.log('Attempting table read');
return context.execute();
});
应用代码
private async Task InitLocalStoreAsync()
{
if (!App.MobileService.SyncContext.IsInitialized)
{
var store = new MobileServiceSQLiteStore("localsync32.db");
store.DefineTable<Nname>();
await App.MobileService.SyncContext.InitializeAsync(store);
}
await SyncAsync();
await RefreshNcards();
}
private async Task SyncAsync()
{
String errorString = null;
string unique = DateTime.Now.Ticks.ToString() + DateTime.UtcNow.TimeOfDay.ToString();
try
{
await LocalCards.PullAsync("Nnames "+unique,LocalCards.CreateQuery()); // first param is query ID, used for incremental sync
}
catch (Exception ex)
{
errorString = "Pull failed: " + ex.Message +
"\n\nIf you are still in an offline scenario, " +
"you can try your Pull again when connected with your Mobile Serice.";
}
if (errorString != null)
{
MessageDialog d = new MessageDialog(errorString);
await d.ShowAsync();
}
}
答案 0 :(得分:0)
显然,PullAsync()命令将查询结果限制为每次50次。所以在我的代码中,我一次只能拉50个项目。要修复我添加了一个最大页面大小的拉动选项Param:
private async Task SyncAsync()
{
String errorString = null;
PullOptions pageSize = new PullOptions { MaxPageSize =1000 };
try
{
await LocalCards.PullAsync("Nname",LocalCards.CreateQuery(), pullOptions: pageSize); // first param is query ID, used for incremental sync
}
catch (Exception ex)
{
errorString = "Pull failed: " + ex.Message +
"\n\nIf you are still in an offline scenario, " +
"you can try your Pull again when connected with your Mobile Serice.";
}
if (errorString != null)
{
MessageDialog d = new MessageDialog(errorString);
await d.ShowAsync();
}
}