Search:
Namespaces
Discussions
.NET v1.1
Feedback
Help - Continuous file reading!
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.general
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
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
Reply to this message...
Herfried K. Wagner [MVP] (VIP)
* Marty <
Click here to reveal e-mail address
> scripsit:
[Original message clipped]
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.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
Marty
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
Herfried K. Wagner [MVP] wrote:
[Original message clipped]
Reply to this message...
Herfried K. Wagner [MVP] (VIP)
* Marty <
Click here to reveal e-mail address
> scripsit:
[Original message clipped]
'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'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
Marty
Marvelous! thanks you. :)
Herfried K. Wagner [MVP] wrote:
[Original message clipped]
Reply to this message...
System.IO.FileAccess
System.IO.FileMode
System.IO.FileShare
System.IO.FileStream
System.IO.StreamReader
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com