2

我的問題很簡單:我們可以在BackgroundTasks中使用MobileServices嗎? (WP 8.1 XAML)Azure MobileService在BackgroundTask

我有一個通用的應用程序連接到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(); 
    } 
} 

這是我加的參考: enter image description here

編輯2 我劇照尋找解決方案,現在我想知道,難道是因爲我超過後臺任務被允許使用的內存量?

回答

0

我不是背景任務的專家,但您確實可以在那裏使用Mobile Services SDK。只需確保後臺任務不會干擾應用程序,方法是使用應用程序設置在兩個進程之間進行鎖定。