locked
file closed, but still not ready to be accessed RRS feed

  • Question

  • How can I check to see if a file is not opened or used? The scenario is that a text file is being created by an external thread. The thread is finished and disposed, and I thought the text file should have been created and channel is released, but it is not! Immediately after i finished that thread, if i try to open the text file for reading, the debugger will stop there (using...end using), until i press F5 again, then it will finish successfully.
    Can any one help?

    Thanks
    Friday, March 30, 2007 5:43 AM

Answers

  • System.Threading.Thread.Sleep(1000)
    this allows the current thread to suspend for 1 second, allowing the text file to be ready for accessing. It worked very well for my case.
    Wednesday, April 4, 2007 3:47 AM

All replies

  • Hello,

     

    how are you creating the file?

    Are you using a streamwriter?

    If yes, then have you added a

    <streamwriter>.Close() command at the end of the thread?

     

    Grtz, Tom.

    Friday, March 30, 2007 2:25 PM
  • Hi,
    Thanks for your reply.
    Actually this text file is created from another executable file written in Fortran. I have made sure that the file channel has been closed at the end.


    Sunday, April 1, 2007 11:28 PM
  • System.Threading.Thread.Sleep(1000)
    this allows the current thread to suspend for 1 second, allowing the text file to be ready for accessing. It worked very well for my case.
    Wednesday, April 4, 2007 3:47 AM