Solved

reading a text file from windows service

Posted on 2004-09-21
5
205 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now