[英]Windows Phone 8.1 - Exception when creating WriteableBitmap from a Background Task
我正在构建Windows Phone 8.1应用程序(Windows运行时,而不是Windows Phone Silverlight 8.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();
}
}
当我运行后台任务时,两个通知均按预期工作,但出现以下异常:
"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条通知,并且不会引发异常。
有任何想法吗?
谢谢。
使用XamlRenderingBackgroundTask
在后台生成XAML图形。 请注意,建议您为此使用C ++,以最大程度地减少内存使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.