0

コードをバッチとして実行しているときに、コードで自分で作成したばかりのファイルを移動しようとすると、 「 System.IO.IOException: The process cannot access the file because it is being used by another process 」というエラーが表示されます。クライアントとして実行しても問題ありません。私はグーゲリングを試しましたが、提案のいくつかは含まれています。以下ですが、うまくいかなかったのでコメントを外しました。(filenameOutTemp は私がアクセスできないものです)

    ...
    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");
    }

誰かが助けてくれることを願っています:)

4

2 に答える 2

1

バッチ内のコードは、確定的なガベージ コレクションを持たない .Net によって実行されます。

AsciiIo オブジェクトをガベージ コレクションするときに AsciiIo ファイルが閉じられるため、これは問題です。

ガベージ コレクタをプログラムで呼び出すことにより、問題を解決できる場合があります。これはバッチでのみ実行してください。

于 2013-12-05T10:32:02.687 に答える
0

同様に静的サーバー メソッドを作成しWinAPIServer::CopyFile(...)、バッチの実行時にそのメソッドを呼び出してみましたか?

于 2013-12-09T23:22:26.283 に答える