C# version - does it implement autoclosable at all? It locks the file when encontering a corrupt pdf...

trevor
2013-09-09
4 days ago
  • trevor
    trevor
    2013-09-09

    Hi folks,

    I see the java version is mentioned that functions auto close, but does this happen in the c# version?

    I am having an issue as follows:

    All my program should do is simply create the File object, like:

    org.pdfclown.files.File mainFile = new org.pdfclown.files.File(fileName)

    Then sometimes there is a corrupt pdf in my list of files, and Itry to catch the exception and move that file to a "bad pdf folder".

    The problem is that when I go to move the file, I am getting an IOException saying that the file is already used by another process.

    I have used many combinations of "using", and disposing of everything, etc. but I simply cannot seem to get org.pdfclown.files.File to release the file without completely exiting the program.

    Catching the ParseException of org.pdfclown does work, I can increment my bad file count and move on to the next files in the folder - but later when I go to my routine to move the bad files, I cannot get the file unlocked.

    Any advice please?

    Thanks kindly!

    Trev

     
  • Equalizer
    Equalizer
    2015-01-06

    Hi Trevor,

    I know this is an older post but it still deserves an answer.

    the C# version does not auto close files so you have to use mainFile.Dispose() before using System.IO.File to manipulate the file, this will force the file to be closed and you can then do with it as you wish.

     
  • Hi Equalizer,

    what do you mean with "the C# version does not auto close files"? AFAIK, as org.pdfclown.files.File implements IDisposable, its Dispose() method should get automatically called after exiting the using block; your suggestion to explicitly invoke it makes sense in case the user needs its disposal before exiting such block -- don't you agree?

    PS: I spotted the lack of finalizer in org.pdfclown.files.File, but apparently this shouldn't affect the case of Trevor -- fixed through IDisposable implementation refinement commit on 0.1.2-Fix branch (rev 141) and 0.2.0 trunk (rev 142).

     
    Last edit: Stefano Chizzolini 4 days ago