【问题标题】:Azure MobileService in BackgroundTask后台任务中的 Azure 移动服务
【发布时间】: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


    【解决方案1】:

    我不是后台任务方面的专家,但您确实可以在那里使用移动服务 SDK。只需确保后台任务不会干扰应用程序,方法是使用应用程序设置在两个进程之间锁定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 2011-05-27
      • 2019-07-30
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多