0

I'm getting the error "System.IO.IOException: The process cannot access the file because it is being used by another process" while trying to move a file i just created myself in the code, while running the code as batch. I have no problems running it as a client. I have tried Googelling and some of the suggestions are incl. below but uncommentted since it did not work. (filenameOutTemp is the one i can't access)

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

hope someone can please help :)

2 Answers2

1

The code in batch is executed by .Net, which do not have deterministic garbage collection.

This is a problem as AsciiIo files are closed when garbage collecting the AsciiIo object!

You may solve the problem by programatically invoking the garbage collector. Only do this in batch!

Community
  • 1
  • 1
Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
0

Have you tried creating a static server method much like WinAPIServer::CopyFile(...) and then calling that method when executing the batch?

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71