my function that gets the stream is
private byte[] download(string url)
{
byte[] buffer = new byte[1024];
try
{
WebRequest req = WebRequest.Create(url);
WebResponse response = req.GetResponse();
buffer = new byte[response.ContentLength];
Stream stream = response.GetResponseStream();
int numBytesRead = stream.Read(buffer, 0, buffer.Length);
}
catch (Exception)
{
MessageBox.Show("There was a problem downloading the file");
}
return buffer;
}
where the url is like "http://img.msg.yahoo.com/avatar.php?yids=ahmedn32004"
and the code in the button click is
byte[] imageData = download(url);
MemoryStream stream = new MemoryStream(imageData);
Image img = Image.FromStream(stream);
avatar.Image = img;
stream.Close();
after this executes it only shows about tenth of the picture not all of it
why the rest of the picture doesn't appear?
it is just a part of it and the rest is black
and another thing
I realized that while the app is sending the request and waiting for an answer it hangs till the answer is received
so I used threading
but when I used that all variables (that are supposed to come from the request answer) are empty
it seems that the thread doesn't wait till the connect method finishes and continue to the next line
I used a void method as the thread starter and in this one there are calls to other methods
what can I do ?

New Topic/Question
Reply




MultiQuote







|