I'm building a Windows Phone 8.1 app (Windows Runtime, not Windows Phone Silverlight 8.1). I have created a Background Task that I trigger by using a Maintenance Trigger. Inside the background task, I need to create a WriteableBitmap from one picture of Camera Roll. My code is as follows:
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();
}
}
When I run the background task, the two notifications work as expected, but I'm getting the following exceptions:
"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)"
If I remove this lines:
using(var fileStream = await files[0].OpenStreamForReadAsync())
{
WriteableBitmap writeableBitmap = await BitmapFactory.New(1, 1).FromStream(fileStream.AsRandomAccessStream());
}
Everything works as expected, the 2 notifications appear and no exception is thrown.
Any ideas?
Thank you.