该进程无法访问文件xxx,因为它正由另一个进程使用。 [英] The process cannot access the file xxx because it is being used by another process.

查看:184
本文介绍了该进程无法访问文件xxx,因为它正由另一个进程使用。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




当我尝试删除pdf文件时收到此消息。



类型'的例外情况System.IO.IOException'发生在mscorlib.dll中但未在用户代码中处理



附加信息:进程无法访问文件xxxx,因为它正在被使用另一个过程。



Hi
I am getting this message when i am trying delete pdf file.

An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code

Additional information: The process cannot access the file xxxx because it is being used by another process."

public PdfView(PdfViewModel viewModel)
        {
            InitializeComponent();
            this.DataContext = viewModel;
            string Exepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string Directory = System.IO.Path.GetDirectoryName(Exepath);
            string Path =  Directory + "\\Payslip.pdf"
           webBrowser1.Navigate(new System.Uri(Path));
          

          
               if (System.IO.File.Exists(Path))
               {
                   File.Delete(Path);
               }
           }

}





有人可以用这个nigtmare来帮助我吗?



提前谢谢



can somebody help me with this nigtmare?

Thanks in advance

推荐答案

如果某个进程访问了某个资源,那么它将拥有一个锁。在这种情况下,没有其他进程可以访问资源。因此,请确保在访问该文件时没有其他进程正在访问该文件。没有办法解决这个问题。要么你必须杀死正在使用该文件的进程,要么保留它。在您的情况下,制作文件的副本并使用它。处理完成后,有2份文件和删除。
If a resource is accessed by a process then it will have a lock.So no other process can access the resource in this case. So make sure when you access the file no other processes are accessing the file. There is no way to fix this issue. Either you have to kill the process which is using the file or leave it like that. In your case make a copy of the file and use it. have 2 copies of file and delete once the processing is done.


这篇关于该进程无法访问文件xxx,因为它正由另一个进程使用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆