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
LVL 1
shahzad73Asked:
Who is Participating?
 
deepaknetConnect With a Mentor Commented:
0
 
deepaknetCommented:
Hi:

You can use the FileSystemWatcher in C#:

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

deepak
0
 
shahzad73Author Commented:

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
0
 
shahzad73Author Commented:
hi deepak

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



Shahzad
0
 
deepaknetCommented:
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).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.