Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've written something very similar. I used the FileSystemWatcher to get notifications about changes. I then used a FileStream to read the data (keeping track of my last position within the file and seeking to that before reading the new data). Then I add the read data to a buffer which automatically extracts complete lines and then outputs then to the UI.</p> <p>Note: "this.MoreData(..) is an event, the listener of which adds to the aforementioned buffer, and handles the complete line extraction.</p> <p>Note: As has already been mentioned, this will only work if the modifications are always additions to the file. Any deletions will cause problems.</p> <p>Hope this helps.</p> <pre><code> public void File_Changed( object source, FileSystemEventArgs e ) { lock ( this ) { if ( !this.bPaused ) { bool bMoreData = false; // Read from current seek position to end of file byte[] bytesRead = new byte[this.iMaxBytes]; FileStream fs = new FileStream( this.strFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite ); if ( 0 == this.iPreviousSeekPos ) { if ( this.bReadFromStart ) { if ( null != this.BeginReadStart ) { this.BeginReadStart( null, null ); } this.bReadingFromStart = true; } else { if ( fs.Length &gt; this.iMaxBytes ) { this.iPreviousSeekPos = fs.Length - this.iMaxBytes; } } } this.iPreviousSeekPos = (int)fs.Seek( this.iPreviousSeekPos, SeekOrigin.Begin ); int iNumBytes = fs.Read( bytesRead, 0, this.iMaxBytes ); this.iPreviousSeekPos += iNumBytes; // If we haven't read all the data, then raise another event if ( this.iPreviousSeekPos &lt; fs.Length ) { bMoreData = true; } fs.Close(); string strData = this.encoding.GetString( bytesRead ); this.MoreData( this, strData ); if ( bMoreData ) { File_Changed( null, null ); } else { if ( this.bReadingFromStart ) { this.bReadingFromStart = false; if ( null != this.EndReadStart ) { this.EndReadStart( null, null ); } } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload