Help - Continuous file reading!

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Hi everybody,

Is it possible to do that in VB.NET: I have a text file that is filled
with new lines of text every n seconds. This text file get very massive.

I want to have my program to monitor this text file and to be able to
read only the new added line when it detect that a new line has been added.

I don't want to read the whole file every time, this would be high time
consuming.

Any idea? Thanks you very much!

Marty
 
* Marty said:
Is it possible to do that in VB.NET: I have a text file that is
filled with new lines of text every n seconds. This text file get
very massive.


I want to have my program to monitor this text file and to be able to
read only the new added line when it detect that a new line has been
added.


I don't want to read the whole file every time, this would be high
time consuming.

Check the file size every n seconds and store the previous file size.
Then you can use the 'FileStream''s 'Seek' method or 'Position' property
to read data beginning at the position where the file ended the last
time you read it.
 
Thanks Herfried,

It work very well.

I have another question, how can I be sure that by reading the file, I
don't interrupt the other process who want to add a text line to it?

This is my reader object settings:
Dim fs As New FileStream(strFilePath, FileMode.Open, FileAccess.Read)
Dim ioFileIN As StreamReader = New StreamReader(fs)

Is there anything else that I can set to have my ioFileIN not holding
the file while reading?

Thanks

Marty
 
* Marty said:
I have another question, how can I be sure that by reading the file, I
don't interrupt the other process who want to add a text line to it?


This is my reader object settings:
Dim fs As New FileStream(strFilePath, FileMode.Open, FileAccess.Read)

'FileStream' provides a ctor that accepts a 'FileShare':

\\\
Public Sub New( _
ByVal path As String, _
ByVal mode As FileMode, _
ByVal access As FileAccess, _
ByVal share As FileShare, _
ByVal bufferSize As Integer, _
ByVal useAsync As Boolean _
)
///

Set 'Share' to 'FileShare.ReadWrite'.
 
Marvelous! thanks you. :)

'FileStream' provides a ctor that accepts a 'FileShare':

\\\
Public Sub New( _
ByVal path As String, _
ByVal mode As FileMode, _
ByVal access As FileAccess, _
ByVal share As FileShare, _
ByVal bufferSize As Integer, _
ByVal useAsync As Boolean _
)
///

Set 'Share' to 'FileShare.ReadWrite'.
 
Back
Top