简体   繁体   中英

Clearing out result from WebClient

I have the follow code section for a web client:

var client = new WebClient();
client.DownloadProgressChanged += (sender, args) => 
client_DownloadProgressChanged(sender, args, this.Context.ConnectionId);
client.DownloadDataCompleted += (sender, evt) =>
{
    byte[] result = evt.Result;
    aLongRunningTask(result);**
}

My problem is that the "aLongRunningTask" function needs to be initiated upon the completion of the downloaddata method, which is working fine, but since the file I receive is very large, I end up having a string in memory taking up a lot of memory space, that there is no need for since I only need byte[].

evt.Result is sadly a readonly property so I can not empty it, and I can not null the client, since I am running the aLongRunningTask.

Is there any way to either overwrite the evt.Result so it can be cleaned, or another way to get that memory usage emptied.

How about using using like this

using(var client = new WebClient()){

//your logic

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM