C# Windows Phone 8.1-从后台任务创建可写位图时出现异常

C# Windows Phone 8.1-从后台任务创建可写位图时出现异常,c#,windows-runtime,windows-phone,windows-phone-8.1,background-task,C#,Windows Runtime,Windows Phone,Windows Phone 8.1,Background Task,我正在构建Windows Phone 8.1应用程序Windows运行时,而不是Windows Phone Silverlight 8.1。我已经创建了一个后台任务,我使用维护触发器触发它。在后台任务中,我需要从一张相机卷的图片创建一个可写的位图。我的代码如下: public sealed class Class1 : IBackgroundTask { public async void Run(IBackgroundTaskInstance taskInstance) {

我正在构建Windows Phone 8.1应用程序Windows运行时,而不是Windows Phone Silverlight 8.1。我已经创建了一个后台任务,我使用维护触发器触发它。在后台任务中,我需要从一张相机卷的图片创建一个可写的位图。我的代码如下:

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个通知,没有引发异常

有什么想法吗


谢谢。

用于在后台生成XAML图形。注意,建议使用C++来最小化内存使用量。

什么是异常消息?我想知道Wrababl位图是否只能在后台任务没有的UI线程上实例化/使用?是的,我的知识位图只能在UI线程上完成。那么,就不可能在BackgroundTask上创建一个WriteableBitmap了?异常消息是:应用程序调用了一个为不同线程封送的接口。来自HRESULT的异常:0x8001010E RPC_E_错误_线程