假设我有这个函数,可以从主线程中多次调用.每次调用它时,我都会创建一个WebClient对象来异步下载一些数据.
我的问题……这样做安全吗?调用事件后是否发布了WebClient对象?如果它不会被自动释放,我不想继续分配内存.
我的应用程序适用于带Silverlight的WP7.
谢谢!
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) { ... }