简体   繁体   English

该进程无法访问文件XXX,因为它正在被另一个进程使用

[英]The process cannot access the file XXX because it is being used by another process

When I run my application, I get this error on the first "using" here: 当我运行我的应用程序时,在第一个“使用”位置出现此错误:

    public void CreateFile(string filePath)
    {

        //Create File
        string fileLoc = filePath;

        FileStream fs = null;
        if (!File.Exists(fileLoc))
        {
            using (fs = File.Create(fileLoc))
            {

            }
        }

    }

    public void WriteFile(string filePath)
    {
        //Write to File
        string fileLoc = filePath;

        if (File.Exists(fileLoc))
        {
            using (StreamWriter sw = new StreamWriter(fileLoc))
            {
                sw.Write("Some sample text for the file");
            }
        }
    }

A file from that directory was previously opened and read from, but the StreamReader was closed after it was read. 该目录中的文件先前已打开并从中读取,但在读取StreamReader之后将其关闭。 I'm not sure if that has any significance with this error. 我不确定此错误是否有意义。 Thanks. 谢谢。

您对出现错误的行之前的File.Exists检查表明发生了奇怪的事情,例如尝试将目录路径用作filePath或多线程竞争条件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该进程无法访问文件“ XXX”,因为它正在被另一个进程使用 - The process cannot access the file 'XXX' because it is being used by another process 如何避免进程无法访问文件XXX.XXX,因为它正被另一个进程使用 - How to avoid from The process cannot access the file XXX.XXX because it is being used by another process 无法加载文件或程序集“ xxx.Data”,因为其他进程正在使用该文件,所以该进程无法访问该文件 - Could not load file or assembly 'xxx.Data' The process cannot access the file because it is being used by another process 该进程无法访问文件“ xxx”,因为使用ReportViewer暴露为PDF时,该进程正在被另一个进程使用 - The process cannot access the file 'xxx' because it is being used by another process when Exporing to PDF using ReportViewer 该进程无法访问文件xxx.xlsx,因为它正在被另一个进程使用 - The process cannot access the file xxx.xlsx because it is being used by another process 该进程无法访问文件“ XXX.txt”,因为它正在被另一个进程使用 - The process cannot access the file “XXX.txt” because it is being used by another process 如果我再次发送,该进程无法访问文件“XXX”,因为它正被另一个进程使用 - The process cannot access the file 'XXX' because it is being used by another process, if i send a second time 错误:该进程无法访问文件“ ...”,因为它正在被另一个进程使用 - Error: The process cannot access the file '…' because it is being used by another process 该进程无法访问该文件,因为它正在被另一个进程使用 - The process cannot access the file because it is being used by another process 该进程无法访问该文件,因为该文件正由另一个进程使用 - The process cannot access the file because it is being used by another process
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM