Hi, I am loading some pictures from a traffic cam website and displaying them in picture boxes but the form freezes because its working too much. Is there any way to speed up the process, here is my code.

string[] picURL = new string[9];
            picURL[0] = "http://www.nzta.govt.nz/traffic/current-conditions/webcams/webcam-images/cst1.jpg?rnd=0.0822959104552865";
            picURL[1] = "http://www.nzta.govt.nz/traffic/current-conditions/webcams/webcam-images/hel1.jpg?rnd=0.9581611268222332";
            picURL[2] = "http://www.nzta.govt.nz/traffic/current-conditions/webcams/webcam-images/hel2.jpg?rnd=0.8423508508130908";
            picURL[3] = "http://www.nzta.govt.nz/traffic/current-conditions/webcams/webcam-images/hel3.jpg?rnd=0.800909330137074";
            picURL[4] = "http://www.citylink.co.nz/images/webcam/aotea.jpg";
            picURL[5] = "http://www.citylink.co.nz/images/webcam/terrace-north.jpg";
            picURL[6] = "http://www.citylink.co.nz/images/webcam/terrace-south.jpg";
            picURL[7] = "http://www.citylink.co.nz/images/webcam/courtenay.jpg";
            picURL[8] = "http://www.citylink.co.nz/images/webcam/mtvic.jpg";

            WebRequest Request1 = WebRequest.Create(picURL[0]);
            WebRequest Request2 = WebRequest.Create(picURL[1]);
            WebRequest Request3 = WebRequest.Create(picURL[2]);
            WebRequest Request4 = WebRequest.Create(picURL[3]);
            WebRequest Request5 = WebRequest.Create(picURL[4]);
            WebRequest Request6 = WebRequest.Create(picURL[5]);
            WebRequest Request7 = WebRequest.Create(picURL[6]);
            WebRequest Request8 = WebRequest.Create(picURL[7]);
            WebRequest Request9 = WebRequest.Create(picURL[8]);

            WebResponse Responce1 = Request1.GetResponse();
            WebResponse Responce2 = Request2.GetResponse();
            WebResponse Responce3 = Request3.GetResponse();
            WebResponse Responce4 = Request4.GetResponse();
            WebResponse Responce5 = Request5.GetResponse();
            WebResponse Responce6 = Request6.GetResponse();
            WebResponse Responce7 = Request7.GetResponse();
            WebResponse Responce8 = Request8.GetResponse();
            WebResponse Responce9 = Request9.GetResponse();

            Image img1 = Image.FromStream(Responce1.GetResponseStream());
            Image img2 = Image.FromStream(Responce2.GetResponseStream());
            Image img3 = Image.FromStream(Responce3.GetResponseStream());
            Image img4 = Image.FromStream(Responce4.GetResponseStream());
            Image img5 = Image.FromStream(Responce5.GetResponseStream());
            Image img6 = Image.FromStream(Responce6.GetResponseStream());
            Image img7 = Image.FromStream(Responce7.GetResponseStream());
            Image img8 = Image.FromStream(Responce8.GetResponseStream());
            Image img9 = Image.FromStream(Responce9.GetResponseStream());

            pictureBox1.Image = img1;
            pictureBox2.Image = img2;
            pictureBox3.Image = img3;
            pictureBox4.Image = img4;
            pictureBox5.Image = img5;
            pictureBox6.Image = img6;
            pictureBox7.Image = img7;
            pictureBox8.Image = img8;
            pictureBox9.Image = img9;

HI, That dosen't really make much sense to me, i was hoping for some code that would allow it all to be done in one line or something similar, also the pictures are jpeg not bitmap, Could you please explain the background worker class?

Thanks for your help, i'm still having trouble with it. I put my code under the dowork event and then called RunWorkerAsync() but an error said it wasn't recognized.

I used

backgroundWorker1.RunWorkerAsync

with the code under the event and it still timeouts after 3 responces.

I figured out how to work it, all the code is in the backgroundworker class however i still get timeout error at 3 responses, any ideas?

This article has been dead for over six months. Start a new discussion instead.