samedi 28 février 2015

Winforms PictureBox.Load / LoadAsync don't work

I am trying to write a simple winform app that gets an xml file with image urls and shows the images: Here is an xml:



<catalog>
<product>
<imageurl>http://ift.tt/1DmECW9;
<product>
<product>
...
<product>
</catalog>


I'm using a backgroung worker for this taks so my code looks like this:



private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
XmlNodeList xnList = doc.SelectNodes(...);
foreach (XmlNode product in xnList)
{
PictureBox img = new PictureBox();
img.Dock = System.Windows.Forms.DockStyle.Fill;
img.Location = new System.Drawing.Point(3, 28);
img.Size = new System.Drawing.Size(194, 94);
img.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;

//img.LoadAsync(product[...].InnerText);

img.Load(product[...].InnerText);
}
}


When I use the img.LoadAsync I don't see any image and when I'm getting up to image number 1990 out of 8700 and the I'm getting this exception:



An exception of type 'System.ComponentModel.Win32Exception' occurred in
System.Windows.Forms.dll but was not handled in user code

Additional information: Error creating window handle.


When I'm using img.Load I sometimes get the image and sometimes I get timeout exception...


This is not a difficult task to do and yet, how can I have a simple code that works ?


Aucun commentaire:

Enregistrer un commentaire