BackgroundTask中的Azure MobileService [英] Azure MobileService in BackgroundTask

查看:62
本文介绍了BackgroundTask中的Azure MobileService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:我们可以在BackgroundTasks中使用MobileServices吗? (WP 8.1 XAML)

My question is pretty simple : Can we use MobileServices in BackgroundTasks? (WP 8.1 XAML)

我有一个通用应用程序从Azure连接到MobileService,我想让BackgroundTask同步我的远程数据库的数据.

I have an universal app connected to a MobileService from Azure and I wanted to let the BackgroundTask synchronize the data of my remote database.

那么,这可能吗?

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运行时组件.

I can't add a reference to my WP project, so how can I get the App.MobileServiceClient? My BackgroundTask project is a Windows runtime component.

我已经通过管理nuGet软件包添加了对Windows Azure移动服务的引用,现在我可以声明一个mobileService,但是当我想实例化它时,出现以下错误:

I've added the reference to Windows Azure Mobile Service by managing nuGet Packages and I can now declare a mobileService but when I want to instanciate it I've got the following error :

BACKGROUNDTASKHOST.EXE' has exited with code 1 (0x1).

这就是我的代码现在的样子:

So this is what my code looks like now :

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

这是我添加的参考:

And this is the reference I've added :

编辑2 我仍在寻找解决方案,我现在想知道,是否可能是因为我超出了后台任务允许使用的内存量?

Edit 2 I'm stills searching for solution and I'm now wondering, could it be because I exceed the amount of memory the background task is allowed to use?

推荐答案

我不是后台任务专家,但是您确实可以在那里使用Mobile Services SDK.通过使用应用程序设置在两个进程之间锁定,只需确保后台任务不会干扰应用程序即可.

I'm not an expert on background tasks, but you can indeed use the Mobile Services SDK there. Just make sure that the background task doesn't interfere with the app, by using an app setting to lock between the two processes.

这篇关于BackgroundTask中的Azure MobileService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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