【发布时间】:2015-05-01 10:04:15
【问题描述】:
我有一个包含很多产品的 xml 文件(10,000 种产品到 200,000 种产品甚至更多),我正在尝试编写一个简单的 winform 来获取此 xml 文件并显示产品图像和数据: 这是和 xml 示例:
<catalog>
<product>
<name>...</name>
<price>...</price>
<description>...</description>
<imageurl>http://www.boscovs.com/wcsstore/boscovs/images/store/product/thumbnails/60314665830t.jpg</imageurl>
<product>
<product>
...
<product>
</catalog>
我正在为这项任务使用背景工作者,所以我的代码如下所示:
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);
this.Invoke(new MethodInvoker(delegate
{
// Execute the following code on the GUI thread.
this.Controls.Add(img);
}));
}
}
当我使用 img.LoadAsync 时,我看不到任何图像,当我从 8700 中获得图像编号 1990 时,我遇到了这个异常:
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.
当我使用img.Load 时,有时会得到图像,有时会出现超时异常...
这不是一项艰巨的任务,但是,我怎样才能有一个可以工作的简单代码?
【问题讨论】:
标签: c# winforms picturebox