【发布时间】:2015-01-01 11:36:07
【问题描述】:
我的问题很简单:我们可以在 BackgroundTasks 中使用 MobileServices 吗? (WP 8.1 XAML)
我有一个从 Azure 连接到 MobileService 的通用应用程序,我想让 BackgroundTask 同步我的远程数据库的数据。
那么,这可能吗?
public sealed class BackgroundTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
//Connect to mobile service and add data
deferral.Complete();
}
}
我无法添加对我的 WP 项目的引用,那么如何获取 App.MobileServiceClient? 我的 BackgroundTask 项目是一个 Windows 运行时组件。
编辑:
我通过管理 nuGet 包添加了对 Windows Azure 移动服务的引用,现在我可以声明一个 mobileService,但是当我想实例化它时,我遇到了以下错误:
BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1).
这就是我的代码现在的样子:
public sealed class BackgroundTask : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
Microsoft.WindowsAzure.MobileServices.MobileServiceClient lolServiceMobileClient =
new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
"https://myservicemobile.azure-mobile.net/",
"myKey");
deferral.Complete();
}
}
这是我添加的参考:
编辑 2 我仍在寻找解决方案,我现在想知道,可能是因为我超出了后台任务允许使用的内存量吗?
【问题讨论】:
标签: xaml windows-phone-8.1 azure-mobile-services background-task