In my mobile app, I want to load all images from an arraylist of links. For each link I create a thread and make httpwebrequest. The problem is that my app run not smooth. It seems to get a delay every time I create new thread and when thread done(when thread done I'll draw the download img onto background). Here's my code:
for (int i = 0; i < NumbersOfImg; i++)
{
if (i < ImgObjArr.Count)
{
ThreadStart myThread = new ThreadStart(getUrlImg);
Thread t = new Thread(myThread);
t.Start();
}
}
private void getUrlImg()
{
MyImage mycurrentImg = (MyImage)ImgObjArr[currentMyImg];
if (currentMyImg < ImgObjArr.Count - 1)
currentMyImg++;
myRequest = (HttpWebRequest)WebRequest.Create(mycurrentImg.ImageLink);
myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream ImgStream = myResponse.GetResponseStream();
mycurrentImg.FullImg = new Bitmap(ImgStream);
this.BeginInvoke(new EventHandler(ImageUpdate));
}
and method ImageUpdate() will draw the Image. And when app navigate to next row, I will create numbers of threads to continue make webrequest. And delay happen when the old thread not complete but I create new threads. So any suggestion why my app had delay? Thanks in advance.