安装Windows补丁后出现文件访问问题 [英] File access issue after installing windows patch

查看:73
本文介绍了安装Windows补丁后出现文件访问问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们开始出现以下错误:



System.IO .IOException:进程无法访问该文件,因为它正由另一个进程使用。



它是在我们安装附加映像中列出的Windows补丁时开始的。 />


IOException随机抛出,处理了30000个文件,大约5个文件将遇到此异常。



我们所做的临时解决方案是将对File.Move()函数的调用更改为一个新函数,如果存在IOException,它将重试。

重试将每次等待1秒尝试5次 - 线程。睡眠(1000)。

此解决方案有效但我们需要对此问题进行永久性修复,因为我们在代码的其他部分也遇到此问题。



源代码:



private void processFiles(string incomingFolder,string processingFolder)

{

     FileInfo [] files = GetFiles(incomingFolder);

    foreach(文件中的var文件)

    {

        File.Move(file.FullName,processingFolder);

    }


    FileInfo [] files2 = GetFiles(processingFolder);

    foreach(文件2中的var文件)

    {

        sampleProcessingMethod(file.FullName);

    }
}





private void sampleProcessingMethod(string filePath)

{

    //获取新文件名 - 只需在文件名中加上时间戳

    string renameTo = GetNewFileName(filePath);



    //将文件重命名为同一文件夹

    File.Move(filePath,renameTo);  //< ---这是抛出IOException的地方

}

Hi,

We started having the error below:

System.IO.IOException: The process cannot access the file because it is being used by another process.

It started when we installed the windows patches listed in the attached image.

The IOException is thrown randomly, with 30000 files processed, around 5 files will encounter this exception.

The temporary solution we did was to change the call to File.Move() function to a new function that will retry if there's an IOException.
The retry will try 5 times each time waiting for 1 second - Thread.Sleep(1000).
This solution worked but we need a permanent fix for this issue as we are encountering this issue in other parts of the codes too.

Source code:

private void processFiles(string incomingFolder, string processingFolder)
{
    FileInfo[] files = GetFiles(incomingFolder);
    foreach(var file in files)
    {
        File.Move(file.FullName, processingFolder);
    }

    FileInfo[] files2 = GetFiles(processingFolder);
    foreach(var file in files2)
    {
        sampleProcessingMethod(file.FullName);
    }
}


private void sampleProcessingMethod(string filePath)
{
    // Get new file name - just appends a time stamp to the file name
    string renameTo = GetNewFileName(filePath);

    // rename the file on the same folder
    File.Move(filePath, renameTo);  // <--- This is where the IOException is thrown
}

推荐答案

这是一个最终用户论坛,因此您无法通过此处告知Microsoft来联系Microsoft。 

This is an end user forum, so you don't reach Microsoft by telling this here. 

在Visual Studio帮助中使用 - >发送反馈

Use in Visual Studio Help -> Send Feedback


这篇关于安装Windows补丁后出现文件访问问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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