locked
Continous Reading From a file.... RRS feed

  • Question

  •  

    Hi,

    I have a requirement wherin i have to display my log file's entries inside my application.So,when i click a button,all the text inside my log file should be read and displayed inside a Rich Textbox.Also,the read operation should be continous..so that when ever the application logs anything inside the log file,i should be able to display it in the Rich text box editor.

    I tried doing it using the Async version of filestream.Beginread...but to get an exception saying...the file is in use by another process(which is my application itself)...Any pointers on ,how to get over this and implement a continous reading mechanism???

    Thanks,
    Mmx

    Thursday, February 14, 2008 6:39 AM

Answers

  • You can use the FileSystemWatcher to watch only one file:

     

    Code Snippet

    FileSystemWatcher watcher;

    watcher = new FileSystemWatcher("C:\\", "test.txt");

    watcher.Changed += new FileSystemEventHandler(watcher_Changed);

    watcher.EnableRaisingEvents = true;

     

     

    wrap it up in a backgroundworker or a thread, if you need it async.
    Thursday, February 14, 2008 2:16 PM

All replies

  • Hi,

     

    you could use the FileSystemWatcher to watch for changes on your file, and whenever it changes update the content of your richtextbox.

     

    Hope this helps!

    Thursday, February 14, 2008 11:35 AM
  • FileSystemWatcher is a solution,but i guess not an elegant one.I'm looking for an Async mechanism in which a thread lies in the background and raises periodic callbacks when it finds that the file is changed explicitly.

     

    Thanks,

    Mmx

     

     

    Thursday, February 14, 2008 12:20 PM
  • You can use the FileSystemWatcher to watch only one file:

     

    Code Snippet

    FileSystemWatcher watcher;

    watcher = new FileSystemWatcher("C:\\", "test.txt");

    watcher.Changed += new FileSystemEventHandler(watcher_Changed);

    watcher.EnableRaisingEvents = true;

     

     

    wrap it up in a backgroundworker or a thread, if you need it async.
    Thursday, February 14, 2008 2:16 PM