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();
}
}
這是我加的參考:
編輯2 我劇照尋找解決方案,現在我想知道,難道是因爲我超過後臺任務被允許使用的內存量?