【发布时间】:2020-01-05 07:54:18
【问题描述】:
我正在使用 Visual Studio 2013 创建一个 c# windows 应用程序,但我遇到了这个错误。
当我尝试删除我一直在图片框中使用的图像时,会出现此错误消息..:
System.IO.IOException:进程无法访问文件 'C:\Users\ALI PC\Documents\My Projects\Doctor Clinic\Doctor Clinic\Images\1.jpg',因为它正被另一个进程使用。
在 System.IO.__Error.WinIOError(Int32 错误代码,字符串可能全路径) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess 访问、Int32 权限、布尔用户权限、FileShare 共享、Int32 bufferSize,FileOptions 选项,SECURITY_ATTRIBUTES secAttrs,字符串 msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
在 System.IO.FileStream..ctor(字符串路径,FileMode 模式,FileAccess 访问、FileShare 共享、Int32 bufferSize、FileOptions 选项、字符串 msgPath, Boolean bFromProxy) 在 System.IO.FileStream..ctor(String 路径,文件模式模式)在 Doctor_Clinic.Forms.ReportForm.deleteBtn_Click(对象发件人, c:\Users\ALI PC\Documents\My Projects\Doctor 中的 EventArgs e) Clinic\Doctor Clinic\Forms\ReportForm.cs:第 94 行
var file = @image;
using (var s = new System.IO.FileStream(file, System.IO.FileMode.Open))
{
PatientImage.Image = Image.FromStream(s);
}
PatientImage.Image = null;
PatientImage.Image.Dispose();
System.IO.File.Delete(file);
【问题讨论】:
-
此链接适用于 vb.net 我正在使用 c# @AjayKumar
-
兄弟,那么您也应该在问题中添加一个 vbNet 标签。
-
@progahmed 但是,框架是相同的,所以例外和解决方案是相同的。只是编程语法不同。
标签: c# image winforms picturebox