The file is locked the first time it is accessed and unlocked after all file operations have ended. I do not see a problem there.
But I think I found the bug. I compared the output of "Process Monitor".
For a file where everything works, the *.jpg file is opened, read and the *.jpgxxx written. After the status "END OF FILE" both files are closed and a CreateFile for the file *.jpg follows.
However, there is no CloseFile in the log for a file with errors.
So this seems to be the own process that is blocking the file.
The file is locked the first time it is accessed and unlocked after all file operations have ended. I do not see a problem there.
But I think I found the bug. I compared the output of "Process Monitor".
For a file where everything works, the *.jpg file is opened, read and the *.jpgxxx written. After the status "END OF FILE" both files are closed and a CreateFile for the file *.jpg follows.
However, there is no CloseFile in the log for a file with errors.
So this seems to be the own process that is blocking the file.