【发布时间】:2014-10-03 21:55:05
【问题描述】:
windows phone 8.1 中的后台任务有 40mb 的有限内存。对于媒体上传到服务器或相关任务,40mb 相当少。
例如:我从 TimerTriggerTask 的 RUN 方法调用下面的函数。
private async void AccessMediaUpload()
{
try
{
// SavedPictures can be used for working with emulators
StorageFolder picfolder = KnownFolders.CameraRoll;
var x = await picfolder.GetFilesAsync();
var enumerator = x.GetEnumerator();
Debug.WriteLine("Number of files are: " + x.Count);
while (enumerator.MoveNext())
{
var file = enumerator.Current;
// Setup the the uploader with the name of the file
var uploader = new BackgroundUploader();
uploader.SetRequestHeader("Filename", file.Name);
// Start the upload
UploadOperation upload = uploader.CreateUpload(uri, file);
await upload.StartAsync();
// Get the HTTP response to see the upload result
ResponseInformation response = upload.GetResponseInformation();
if (response.StatusCode == 200)
{
Debug.WriteLine(file.Name + " Uplaoded");
}
//Debug.WriteLine("HTTP Status Code:" + response.StatusCode);
}
_deferral.Complete();
}
catch (OutOfMemoryException e)
{
Debug.WriteLine(e.Message);
}
}
如果我要上传大约 10 张图片,由于 OutOfMemoryException,它会在 4 张图片后消失。
有没有办法在这里处理内存?请注意,我使用的是后台传输网络 API,它自己完成所有文件分块。
【问题讨论】:
-
您是否尝试过分析您的后台任务以查看是什么占用了这么多内存?
-
我确实使用了 Windows phone 电动工具。它超过 40Mb,这就是后台任务死亡的时候。
标签: c# windows-phone windows-phone-8.1 background-task