• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

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
0
shahzad73
Asked:
shahzad73
  • 3
  • 2
1 Solution
 
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
 
deepaknetCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now