2011-06-02 63 views
0

我下載的圖片來自特定的URL使用for循環的情況下,一些產品有超過5個圖像..當我點擊產品按鈕一些圖像只下載並不是所有的圖像..但是當我debugg的coressponding代碼會下載所有圖像..怎麼可能......圖片沒有正確下載

這是我的代碼

for (int i = 0; i < obj.Count; i++) 
      { 
       PartNAme = (obj[i].ToString().Split('='))[1]; 
       _prtnm = PartNAme.ToString().Split(';')[0]; 


       _final_URI = _URI + _Prod_name + '/' + _prtnm + ".GIF"; 


       WebClient client = new WebClient(); 

       string strtempname = DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", ""); 

       rnd = new Random(100); 

       string _strfile = "PNImage" + strtempname + rnd.Next().ToString() + ".gif"; 

       string _path = "../Images/PNImage/" + _strfile; 

       string _PPath = Server.MapPath(_path);    

        client.DownloadFile(_final_URI, _PPath); 
} 
+0

我不是這方面的專家,但你有沒有嘗試過使用DownloadFileAsync? http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadfileasync(v=vs.80).aspx – 2011-06-02 05:59:49

回答

0

我認爲這是隨機變量會導致這個問題。嘗試將 rnd = new Random(100)從循環中取出並查看它是如何工作的。通常,如果運行速度很快,那麼隨機數就是相同的值。

+0

thanks mR.hOWARD..it將工作正常我要改變隨機數在一個單獨的功能現在它會正常工作 – Anto 2011-06-02 07:51:08

+0

不客氣,我曾經有類似的問題。 – Howard 2011-06-02 08:31:54