2013-04-10 17 views
0

我很困惑的東西。MS.Internal.InternalMemoryStream在後臺代理中變爲MS.Internal.ReadOnlyBufferedStream?

我有一個Windows Phone 8應用程序,它利用後臺代理計劃任務。

其中,後臺代理下載並使用unzipper found here提取.zip文件。 (解壓縮功能在應用程序的常規非背景部分中工作正常。)

我注意到後臺代理正在拋出一個System.NotImplementedException,並且我將其跟蹤到Unzipper.ParseCentralDirectory中的一行代碼

public sealed class Unzipper : IDisposable 
{ 
    private Stream stream; 
    ... 

正如我所提到的,unzipper功能可以運行在常規精細:()

private List<FileEntry> ParseCentralDirectory() 
{ 
    BinaryReader reader = new BinaryReader(this.stream); 
    //this next line is the one that's throwing the System.NotImplementedException 
    reader.BaseStream.Seek(-4, SeekOrigin.End); 

在這種情況下,在BinaryReader在參數「this.stream」是在類的頂部限定主要應用。所以我在主應用程序和後臺應用程序之間尋找代碼段的差異(解壓器類在主項目和後臺代理項目中分別出現)。

我注意到流Unzipper(引用爲「this.stream」)是一個MS.Internal.InternalMemoryStream。但是,當後臺代理在後臺Unzipper.cs中到達同一行時,「this.stream」是MS.Internal.ReadOnlyBufferedStream。

這是我發現的唯一區別。但是,我甚至不確定這是否是問題。它扔System.NotImplementedException上

reader.BaseStream.Seek(-4, SeekOrigin.End); 

但MS.Internal.ReadOnlyBufferedStream呢,其實,有「真」(一個「CanSeek」財產我注意到Unzipper檢查,並引發NotSupportedException如果是假的。)

我在這裏難住了。實際上,使用Google搜索「MS.Internal.ReadOnlyBufferedStream」不會產生單一結果(儘管我猜測它現在會......)

回答

1

與大多數基於網絡的API的前景對應物相比,背景代理具有顯着不同的實現。

我所能推薦的是將數據流傳輸到一個臨時文件在獨立存儲中,然後打開一個流到文件解壓縮。請記住,您只有6mb的內存(RAM)可供玩,包括您的應用程序程序集,之後您的任務將終止(如果發生3次,則不定期)。這可能會導致解壓縮時出現內存問題。

+0

謝謝你的迴應。我嘗試了這種方法,將文件下載到獨立存儲中,然後打開一個isolationStorageStream並將其傳遞給Unzipper的一個新實例。這會拋出「System.ArgumentException:流不可讀」。 – 2013-04-11 22:06:00

+0

另外,您能否詳細說明基於網絡的API在後臺agnets中的差異?我似乎無法找到任何信息。 – 2013-04-14 22:22:18

+0

您的第一個問題聽起來像是在將文件流傳遞到壓縮庫之前處理文件流。 – 2013-04-15 08:26:18