今天很SB,被這個問題卡住了。那段代碼也是網上找的。結果發現只能下載一個文件,第二次下載的時候就會出現“操作超時”的問題。
這個是原代碼:
System.Net.WebClient wc = new System.Net.WebClient();
wc.OpenRead("http://patrickkroft.com/mp3/Pearl.mp3");
Int64 bytes_total= Convert.ToInt64(wc.ResponseHeaders["Content-Length"])
MessageBox.Show(bytes_total.ToString() + " Bytes");
以上的代碼實在是很不負責,坑爹的寫的。改進成下面:
System.Net.WebClient wc = new System.Net.WebClient();
Stream stream = wc.OpenRead(folderEntity.URI);
Int64 bytes_total = Convert.ToInt64(wc.ResponseHeaders["Content-Length"]);
stream.Close(); //以及釋放內存
wc.Dispose();//及時釋放,避免第二次下載時, 奇怪的"操作超時"的問題