Windows Phone 8.1 アプリ (Windows Phone Silverlight 8.1 ではなく Windows ランタイム) を作成しています。メンテナンス トリガーを使用してトリガーするバックグラウンド タスクを作成しました。バックグラウンド タスク内で、カメラ ロールの 1 つの画像から WriteableBitmap を作成する必要があります。私のコードは次のとおりです。
public sealed class Class1 : IBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
var files = await KnownFolders.CameraRoll.GetFilesAsync();
ShowNotification("Process has started");
using(var fileStream = await files[0].OpenStreamForReadAsync())
{
WriteableBitmap writeableBitmap = await BitmapFactory.New(1, 1).FromStream(fileStream.AsRandomAccessStream());
}
ShowNotification("Process has ended");
deferral.Complete();
}
}
バックグラウンド タスクを実行すると、2 つの通知は期待どおりに機能しますが、次の例外が発生します。
"A first chance of exception of type "System.Exception" occurred in WriteableBitmapEx.WinRT.DLL""
"A first chance of exception of type "System.Exception" occurred in mscorlib.dll"
"The proccess has ended with code 1 (0x1)"
この行を削除すると:
using(var fileStream = await files[0].OpenStreamForReadAsync())
{
WriteableBitmap writeableBitmap = await BitmapFactory.New(1, 1).FromStream(fileStream.AsRandomAccessStream());
}
すべてが期待どおりに機能し、2 つの通知が表示され、例外はスローされません。
何か案は?
ありがとうございました。