嗨,我有以下功能:
private void CreateRoomImage(string path)
{
Directory.CreateDirectory(path);
var file = "";
foreach (PanelView panelView in pv)
{
var RoomImage = GetRaumImageName(panelView.Title);
file = path + GetImageFile(RoomImage);
if (File.Exists(file))
{
File.Delete(file);
}
using (var img = GetRaumImage(panelView.Title, panelView))
{
ImageWriter imgWriter = new ImageWriter(ImageFormat.Bmp);
imgWriter.Save(img, file);
}
}
}
我的问题是,每次我尝试删除现有文件时,我的程序都会抛出异常:
The process can not access the file because it is being used by another process
这个问题有解决方案吗?如何删除现有图像?