我使用下面的代码下载文件。但是,在退出程序之前,我无法删除它们。我错过了诸如Dispose()
或Close()
来电之类的内容吗?
int i = 0;
foreach (var item in postTitles)
{
try
{
using (WebClient client = new WebClient())
{
client.DownloadFile(new Uri(item.ToString()), Application.StartupPath + "\\Downloads\\" + i + ".png");
}
i++;
}
catch {}
}
我在列表视图中使用这些图片:
private void ImagesToListView()
{
listView1.Items.Clear();
ImageList imgs = new ImageList();
List<string> imgsPath = new List<string>();
DirectoryInfo di = new DirectoryInfo(inputPath);
FileInfo[] picFiles = di.GetFiles("*.png");
foreach (FileInfo finfo in picFiles)
{
imgs.Images.Add(Image.FromFile(finfo.Fullname));
imgsPath.Add(finfo.FullName);
}
DirectoryInfo di2 = new DirectoryInfo(inputpath);
FileInfo[] picFiles2 di2.GetFilse("*.jpg");
foreach (FileInfo fifnfo2 in picFiles2)
{
imgs.Images.Add(Image.FromFile(finfo2.FullName));
imgsPath.Add(finfo2.FullName);
}
listView1.View = View.Details;
imgs.ImageSize = new Size(80, 80);
listView1.SmallImageList = imgs;
for (int j = 0; j < imgs.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
listView1.Items.Add(item);
item.SubItems.Add(imgsPath[j].ToString());
}
}
这是我的例外:
我使用了listview1.Items.Clear()
,但它并没有解决我的问题。我认为这与我的清单有关。我应该清除我的清单吗?