簡體   English   中英

Windows Phone 8.1-從后台任務創建WriteableBitmap時發生異常

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM