CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    20

    Reading file that is being writen by another app

    Hi,
    little explanation of my problem:
    there is an third party app, that i have no control of.
    this app writes log file, but its not : write all, then close file, its writing when something happen,
    app does not exclusively lock file
    i want to be notified whenever that app writes something to file and read new content
    is there any proper way of dealing with that kind of situation ?

    1) i have tried FileSystemWatcher, to check if files was changed, but it notifies me only on app opening/closing file, not on every write

    2) i am able to read file just the way i want using FileStream.BeginRead, but its using 100% cpu,
    and spams read operations like crazy, i can successfully lower cpu usage by Thread.Sleep, but i think its not what async operations are for ?

    any advice is appreciated

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Reading file that is being writen by another app

    You could simply read the file inside of a timer loop. Read the file until you hit the end, save the index, start next time from that index. You are pegging the CPU because you are doing it inside of a tight loop which obviously won't work (and is a bad idea anyhow).

  3. #3
    Join Date
    Aug 2009
    Posts
    20

    Re: Reading file that is being writen by another app

    thanks for advice, i will do it as you suggested

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