我使用for循环从特定URL下载图像,以防某些产品有超过5个图像..当我点击产品按钮时,某些图像只下载并非所有图像..但是当我调试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 :(得分:0)
我认为这是随机变量导致此问题。试着把 rnd = new Random(100)离开循环,看看它是如何工作的。通常,如果随机运行得很快,则随机值相同。