【发布时间】:2020-09-21 14:24:38
【问题描述】:
使用打开文件对话框在我的应用程序中打开照片后,除非我关闭我的应用程序,否则我无法对文件执行任何操作。我已将 OpenFile 对话框放在 using 语句中,并尝试了各种方法来释放资源,但均未成功。如何释放进程以避免错误消息“该进程无法访问该文件,因为它正在被另一个进程使用?
using (OpenFileDialog GetPhoto = new OpenFileDialog())
{
GetPhoto.Filter = "images | *.jpg";
if (GetPhoto.ShowDialog() == DialogResult.OK)
{
pbPhoto.Image = Image.FromFile(GetPhoto.FileName);
txtPath.Text = GetPhoto.FileName;
txtTitle.Text = System.IO.Path.GetFileNameWithoutExtension(GetPhoto.FileName);
//GetPhoto.Dispose(); Tried this
//GetPhoto.Reset(); Tried this
//GC.Collect(): Tried this
}
}
【问题讨论】:
标签: c# openfiledialog