假设我有一个可以从主线程调用多次的函数。每次被调用时,我都会创建一个WebClient
对象异步下载一些数据。
我的问题...这样做安全吗?是个WebClient
调用事件后释放对象?如果内存不会自动释放,我不想继续分配内存。
我的应用程序适用于带有 Silverlight 的 WP7。
Thanks!
void DownloadData(string cURL)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted +=
new System.Net.DownloadStringCompletedEventHandler(
webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(cURL));
}
static void webClient_DownloadStringCompleted(object sender,
System.Net.DownloadStringCompletedEventArgs e)
{
...
}
The 银光版WebClient http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=VS.95%29.aspx不执行IDisposable
。你做对了——webClient
到时候会自动进行垃圾收集。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)