Solved

reading a text file from windows service

Posted on 2004-09-21
5
208 Views
Last Modified: 2010-04-17
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
Comment
Question by:shahzad73
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:deepaknet
ID: 12110425
Hi:

You can use the FileSystemWatcher in C#:

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

deepak
0
 
LVL 1

Author Comment

by:shahzad73
ID: 12110538

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
 
LVL 15

Accepted Solution

by:
deepaknet earned 50 total points
ID: 12110607
0
 
LVL 1

Author Comment

by:shahzad73
ID: 12110742
hi deepak

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



Shahzad
0
 
LVL 15

Expert Comment

by:deepaknet
ID: 12110819
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 123
groupSumClump challenge 9 137
Java Loop 6 73
in SAS how to create a record for each combination of the two duplicates? 16 111
This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question