c# - WebClient throws exception on second download atttempt -


I am trying to write a random wallpaper downloader for my desktop. The code works fine on the first download but hangs and throws an exception on the second attempt. I tried to dip a customer and start with a new web client. Thanks also in advance I tried without settlement. Public class ChangeWallpaper {[DllImport ("user32.dll", Charset = Charset.auto)] Stable extern int system ParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); Public Stable Zero Main () {Random fileNumber = New Random (); String pathstart = "http://www.starcraft2.com/images/screenshots/ss"; String pathind = "-heres.jpg"; While (true) // always loop {string randomFile = fileNumber.Next (1, 126) .toString (); Web client client = new webclient (); // OK the first time - & gt; The second challenge is to reprimand! Client Download file (PathStart + Undfinite + Pathind, "Picture .JPG"); Client.Dispose (); Try removing // bitmap BM = new bitmap (Image.FromFile ("pic.jpg")); BM. Save ("pic.bmp", imageform.bmp); Bm.Dispose (); // tried to delete - no help systemParametersInfo (20, 0, "pic.bmp", 0x01 | 0x02); Thread.Sleep (60000); // sleep for a minute}}}

Try renaming the file. It is quite likely that when you are trying for a second time, they have file lock on pic.jpg or pic.bmp. Choose one more unique file name each time.

  Client. Download file (path-start + undfinite + pathend, "pic.jpg");  

Perhaps the pic.jpg failed to overwrite. Try to increase the number during the loop (pic1, pic2, etc.) for an exam. You can also come up with a better naming scheme later.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -