0
我的項目中使用HttpWebRequest來下載Feed時如何克服高內存。但是,當我下載,內存增加,當他們返回到以前的形式沒有減少:如何在使用HttpWebRequest來下載
#region RequestDataFromServer
private void RequestDataFromServer(object o)
{
if (!string.IsNullOrEmpty(ServerUri))
{
if (DownloadStatus == DownloadState.Downloading)
return;
DownloadStatus = DownloadState.Downloading;
HttpWebRequest serverRequest = (HttpWebRequest)WebRequest.Create(ServerUri);
serverState = new ServerRequestUpdateState();
serverState.AsyncRequest = serverRequest;
IAsyncResult result =
(IAsyncResult)serverRequest.BeginGetResponse(new AsyncCallback(RequestResponse), serverState);
}
}
#endregion
#region RequestResponse
void RequestResponse(IAsyncResult asyncResult)
{
var offlineStream = IsolatedStorageSettings.ApplicationSettings;
serverState = (ServerRequestUpdateState)asyncResult.AsyncState;
HttpWebRequest serverRequest = (HttpWebRequest)serverState.AsyncRequest;
try
{
serverState.AsyncResponse = (HttpWebResponse)serverRequest.EndGetResponse(asyncResult);
if (serverState != null)
{
Stream stream = serverState.AsyncResponse.GetResponseStream();
if (stream != null && serverState.AsyncResponse.StatusCode == HttpStatusCode.OK)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
DownloadStatus = DownloadState.FileReady;
if (serverState != null)
{
try
{
if (offlineStream.Contains("streamOffline"))
{
offlineStream["streamOffline"] = null;
offlineStream.Remove("streamOffline");
}
offlineStream.Add("streamOffline", stream);
if (onComplete != null)
onComplete.Invoke(this, DownloadStatus, IndexImg);
stream.Close();
stream.Dispose();
stream = null;
}
catch (Exception)
{ }
}
});
}
}
}
catch (WebException ex)
{
DownloadStatus = DownloadState.Error;
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
//if (onComplete != null)
// onComplete.Invoke(this, DownloadStatus, null, IndexImg);
});
}
catch (Exception)
{ }
finally
{
serverRequest = null;
}
}
#endregion
我想我已經銷燬了所有的東西,可以增加內存,但內存仍然是非常高的了,我救了Isostorage流我進入,但它仍然不會減少
爲什麼你使用空的catch塊?你吞下例外,也許有問題 –
@lukas!非常感謝 !我會檢查它,但爲什麼我下載它時增強了內存,但我必須全部取消 – thongaduka