System.IO异常该进程无法访问该文件,因为该文件已被另一个文件使用 [英] System.IO Exception The process cannot access the file because it is used by another

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

问题描述

大家好,
System.IO异常进程无法访问文件,因为它被另一个进程使用,引发了异常
但是在我的代码中,我已经使用了block以及close,但是也抛出了异常,我该怎么办?
一个过程是在写文件的同时读取文件的内容,当时发生异常如何避免呢?

Hello All,
System.IO Exception The process cannot access the file because it is used by another process exception is thrown
but in my code i have used using block as well as close also but also exception is thrown what shall i do for this?
One process is reading the contents of file while writing the file at that time exception is occured how to avoid this?

private static void WritToXmlFile(string xmlfile, XmlDocument doc)
       {
         using (StreamWriter sw = new StreamWriter(xmlfile, false))
               {
                   sw.Write(doc.OuterXml);
                   sw.Close();
               }
      }

推荐答案

可能会将您文件的保存位置设为只读,
may b the location where ur file is saved is readonly,


关闭Visual Studio.然后重新启动,然后尝试在不调试的情况下运行您的应用程序.
Close visual studio. And restart then Try to run your application without debugging.


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

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