Axapta System.IO.File::Move失败,进程无法访问该文件,因为另一个进程正在使用该文件

Axapta System.IO.File::Move失败,进程无法访问该文件,因为另一个进程正在使用该文件,axapta,x++,ax,dynamics-ax-2012-r2,Axapta,X++,Ax,Dynamics Ax 2012 R2,在尝试移动我在代码中刚刚创建的文件时,当以批处理方式运行代码时,出现错误“System.IO.IOException:进程无法访问该文件,因为它正被另一个进程使用”。我作为客户机运行它没有问题。我尝试过谷歌搜索,其中一些建议包括在下面,但没有注释,因为它不起作用。(filenameOutTemp是我无法访问的文件) 希望有人能帮忙:)批处理的代码是由.Net执行的,它没有确定性垃圾收集 这是一个问题,因为当垃圾收集AsciiIo对象时,AsciiIo文件被关闭 你可以用电脑解决这个问题。 只能批

在尝试移动我在代码中刚刚创建的文件时,当以批处理方式运行代码时,出现错误“System.IO.IOException:进程无法访问该文件,因为它正被另一个进程使用”。我作为客户机运行它没有问题。我尝试过谷歌搜索,其中一些建议包括在下面,但没有注释,因为它不起作用。(filenameOutTemp是我无法访问的文件)


希望有人能帮忙:)

批处理的代码是由.Net执行的,它没有确定性垃圾收集

这是一个问题,因为当垃圾收集AsciiIo对象时,AsciiIo文件被关闭

你可以用电脑解决这个问题。
只能批量进行

您是否尝试过创建一个类似于
WinAPIServer::CopyFile(…)
的静态服务器方法,然后在执行批处理时调用该方法?

类似于我自己的问题:(如果所有其他操作都失败,请重新启动AOS,尝试实例化System.Diagnostics.Process并执行“移动”命令,这是最后的手段。为什么您的权限被注释掉了?
    ...
    asciiIoOut   = new AsciiIo(filenameOutTemp, #io_append);
    asciiIoOut.outFieldDelimiter(#fieldDelimiter);      

    if (createFile)
        {
            // Replace the vend account from DDD with local:
            record = conpoke(record, colVendDDD, vendSetupDDD.VendAccount);
            asciiIoOut.writeExp(record);
        }
    }

    //CodeAccessPermission::revertAssert();
    asciiIoOut.finalize();
    asciiIoOut = null;


    //Move from temp folder to vender item folder:
    fshVendTable = RetailVendTable::find(vendSetupDDD.VendAccount);
    filenameOut  = fshVendTable.filePathImport(VendorFileImportPath::Items);
    filenameOut += #filePathSeperator + substr(inventImportFiles.Filename,1, strLen(inventImportFiles.Filename) - 4 );
    filenameOut += #spacer + #item + #spacer + filenameDate + #spacer + filenameTime + #csv;

    //new InteropPermission(InteropKind::ClrInterop).assert(); // get dll interop permission
    try {
        System.IO.File::Move(filenameOutTemp, filenameOut);
    }
    catch(Exception::Error) {
         warning("move failed");
    }