image - Windows 应用程序 (C#) - 进程无法访问该文件,因为它正被另一个进程使用
问题描述
我正在用 C# 编写一个 winform 应用程序来更新图像。
首先,我检查oldfilepath
和newfilepath
是否相似,如果不相似,则删除旧图像并将新图像添加到创建的文件夹(命名为“图像”),并更新数据库中的新文件路径。
但是当我点击更新按钮时,它会显示错误
"The process cannot access the file because it is being used by another process"
string oldpath;
if (File.Exists(Path.Combine(oldpath))) //oldpath where i'm getting the old file path
{
File.Delete(Path.Combine(oldpath));
if (File.Exists(Path.Combine(oldpath)))
{
File.Delete(Path.Combine(oldpath));
}
}
有人可以帮我吗?
解决方案
oldpath 中提到的文件可能在其他进程中实际打开(例如,用它打开的记事本)。检查是否如此,然后关闭该进程。
推荐阅读
- machine-learning - 解释分类模型结果
- c# - 在程序集中找不到 System.Media
- apache-kafka-streams - Kafka Streams KTable 状态存储的不同 serde
- python - 对所有轴的 2D Tensorflow 进行排序
- linux - 我可以在 mysqldump cronjob 中使用波浪号 ( ~ ) 吗?Linux Cron 没有运行
- javascript - 为什么 Internet Explorer 不能以一致的方式处理相同的代码?
- vba - 循环遍历 Excel 表格并创建图表
- amazon-web-services - 是否有 AWS / Pagerduty 服务在未收到通知时会提醒我
- reporting-services - 在 SSRS 中使用查找
- php - 将 HTML 表中的多行插入数据库