CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Oct 2008
    Posts
    1

    Reading a File with Share Privledges

    I've written a program that watches a directory for a file to be created, then saves the path to that file. It then watches that file for any change and, upon change, opens the file, reads through the file and returns the last line, then closes the file. I suspect that there might be a better way to read only the newest lines, but I haven't looked into that yet. My code seems to be working, so I started to test with it.

    While in testing, I noticed that a great deal of lines were getting missed, but not by my program. The writer wasn't writing the file. I thought it might be a limitation of the writer, but upon closing my file, it was back to writing to the text file at 100%. I took a deeper look into it and my call to open the file seems to be locking out the program that writes to it, even though I have the privileges set to read only and share. When mine is open, if two or more lines are added at "the same time," only one line will be written to the text file. In other words, it isn't writing to the file whenever my program is looking at it.

    Is there any way I can read the contents of this file as it's being modified without stopping the writer from being able to add lines?
    Last edited by CyrilCade; October 12th, 2008 at 11:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured