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,它自己完成所有文件分块。