try
{
this.Invoke((MethodInvoker)delegate
{
Uri uri = new Uri("mywebpage.com");
NetworkCredential credentials = new NetworkCredential("username", "password");
byte[] lnBuffer;
byte[] lnFile;
HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create(uri);
lxRequest.Credentials = credentials;
// the line below throws a webexception that for some reason is not being caught by my webexception catch statement.
using (HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse())
{
using (BinaryReader lxBR = new BinaryReader(lxResponse.GetResponseStream()))
{
using (MemoryStream lxMS = new MemoryStream())
{
lnBuffer = lxBR.ReadBytes(1024);
while (lnBuffer.Length > 0)
{
lxMS.Write(lnBuffer, 0, lnBuffer.Length);
lnBuffer = lxBR.ReadBytes(1024);
}
lnFile = new byte[(int)lxMS.Length];
lxMS.Position = 0;
lxMS.Read(lnFile, 0, lnFile.Length);
lxMS.Close();
lxBR.Close();
}
}
lxResponse.Close();
}
using (MemoryStream lxFS = new MemoryStream(lnFile))
{
lxFS.Write(lnFile, 0, lnFile.Length);
lxFS.Position = 0;
Image resizedimage = new Bitmap(Image.FromStream(lxFS), new Size(320, 240));
pictureBox23.Image = resizedimage;
//otherform.picboximage = Image.FromStream(lxFS);
lxFS.Close();
}
});
}
catch (WebException e)
{
this.Close();
}
catch (InvalidOperationException e)
{
this.Close();
}
上記のコメントのある行は Web 例外をスローしますが、webexceptions の catch ステートメントはそれをキャッチしていません。何か案は?ありがとう