Link to home
Start Free TrialLog in
Avatar of shahzad73
shahzad73

asked on

reading a text file from windows service

Hi

I have developed a windows service which monitors the text file. Windows service checks the file 2 times in a second depending on the frequency it is set.

I want to know how to detect whether a new line is added or multiple lines has been added. If added then I want to read those lines.


My windows service has a timer that triggers every 2 times in a second.


any code will be highly appriciated.


Shahzad Aslam
Avatar of Deepak Vasudevan
Deepak Vasudevan
Flag of India image

Hi:

You can use the FileSystemWatcher in C#:

http://www.c-sharpcorner.com/3/FSWatcherMB.asp

deepak
Avatar of shahzad73
shahzad73

ASKER


deepak

but i want to use this in windows service while this component raises events. where will i get the event in windows service



Shahzad
ASKER CERTIFIED SOLUTION
Avatar of Deepak Vasudevan
Deepak Vasudevan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi deepak

can you tell me how .net can open a file for reading while it is being opened by another process.



Shahzad
Hi Shahzad:

You do not need to open a file to check its change. The FileSystemWatcher has an event handler which

System.IO.FileSystemEventArgs e

(This has members like name of the file changed in the path being modified).