Get image from web server with threading

G

Guest

Hi all im having a little difficulty with the below code

try
request = System.Net.HttpWebRequest.Create(Me.TextBox1.Text)
response = request.GetResponse()
responseStream = response.GetResponseStream()
bitmap2 = New Bitmap(responseStream)
PictureBox1.Image = bitmap2
response.Close()

Catch ex As System.Net.WebException
Me.Timer1.Enabled = False
MessageBox.Show("There was an error opening the image file.
Check the URL")
end try

I have the following dec's

Dim bitmap2 As Bitmap
Dim responseStream As System.IO.Stream
Dim response As System.Net.WebResponse
Dim request As System.Net.WebRequest

The above works but i get a few errors about unrecognised stuff but it
works. But it ties up the gui so i assumed i could add it to a seperate
thread like:-
Try

Dim thrMyThread As New
System.Threading.Thread(AddressOf updateimage)

thrMyThread.Start()
Catch
End Try

and wrap the first set of code into a sub called updateimage
But it fails with a unknown object type,

If i comment out the threading call and call the code i get no error so
i assume this is a threading issue somewhere.

Assuming i may be way off i am trying to download an image from a
website that changes every 10 seconds. I want to grab this image and
display it in a picturebox.
Im using vs 2005 and cf 2.0 on a wm5 ppc phone ed device (imate jamin)

Cheers
James
 
G

Guest

Here we go again and again...

When updating UI from a different thread you MUST use the Control.Invoke.
Search for the samples on the web.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top