473,503 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Watching for changes in a file.

I've got an application that I'm modifying and the client needs it to
watch a particular file and then do some stuff when that file gets
modified. For example, let's say the file is C:\Test.dat and that it
looks like this...

AcctNum, 500
SomeValue, 4500

Periodically there is another program that changes the Test.dat file
values. The application I'm modifying needs to detect that the Test.dat
file has been modified, read it and then do some stuff with the values.
This isn't supder difficult. I can just place a timer in the
application that checks the File.GetLastWriteTime method for Test.dat
and then acts appropriately. However, that seems kind of inefficient.
Is there an event or something that I can latch onto to accomplish the
same thing without having to constantly fire a timer off?

Thanks for any help.

Andrew Cooper
Jun 27 '08 #1
5 1172
On Jun 18, 5:48*pm, Andrew Cooper <kairoscreat...@gmail.comwrote:
I've got an application that I'm modifying and the client needs it to
watch a particular file and then do some stuff when that file gets
modified. *For example, let's say the file is C:\Test.dat and that it
looks like this...

AcctNum, 500
SomeValue, 4500

Periodically there is another program that changes the Test.dat file
values. *The application I'm modifying needs to detect that the Test.dat
file has been modified, read it and then do some stuff with the values.
* This isn't supder difficult. *I can just place a timer in the
application that checks the File.GetLastWriteTime method for Test.dat
and then acts appropriately. *However, that seems kind of inefficient.
Is there an event or something that I can latch onto to accomplish the
same thing without having to constantly fire a timer off?

Thanks for any help.

Andrew Cooper
Hi,
As i understand from your needs, you'd better think of FileSystemWatch
component in your toolbox, get more info here:
http://msdn.microsoft.com/en-us/libr...emwatcher.aspx

Thanks,

Onur Güzel
Jun 27 '08 #2
Hoi, you could try the FileSystemWatcher class
(http://msdn.microsoft.com/fr-fr/libr...er(VS.80).aspx)
assulming you can't change how information is exchanged between these two
progs...

--
Patrice

"Andrew Cooper" <ka************@gmail.coma écrit dans le message de groupe
de discussion : e5**************@TK2MSFTNGP06.phx.gbl...
I've got an application that I'm modifying and the client needs it to
watch a particular file and then do some stuff when that file gets
modified. For example, let's say the file is C:\Test.dat and that it
looks like this...

AcctNum, 500
SomeValue, 4500

Periodically there is another program that changes the Test.dat file
values. The application I'm modifying needs to detect that the Test.dat
file has been modified, read it and then do some stuff with the values.
This isn't supder difficult. I can just place a timer in the application
that checks the File.GetLastWriteTime method for Test.dat and then acts
appropriately. However, that seems kind of inefficient. Is there an event
or something that I can latch onto to accomplish the same thing without
having to constantly fire a timer off?

Thanks for any help.

Andrew Cooper

Jun 27 '08 #3
Thanks folks!

I knew there had to be a way to do that without a timer.
FileSystemWatcher is exactly what I need.

Also, Patrice, unfortunately I can't change how these programs
communicate. The other program is proprietary and modifying this file
is the most it will do to help me out. I'd much rather use a socket
connection or something to communicate but... alas!

Andrew

Andrew Cooper wrote:
I've got an application that I'm modifying and the client needs it to
watch a particular file and then do some stuff when that file gets
modified. For example, let's say the file is C:\Test.dat and that it
looks like this...

AcctNum, 500
SomeValue, 4500

Periodically there is another program that changes the Test.dat file
values. The application I'm modifying needs to detect that the Test.dat
file has been modified, read it and then do some stuff with the values.
This isn't supder difficult. I can just place a timer in the
application that checks the File.GetLastWriteTime method for Test.dat
and then acts appropriately. However, that seems kind of inefficient.
Is there an event or something that I can latch onto to accomplish the
same thing without having to constantly fire a timer off?

Thanks for any help.

Andrew Cooper
Jun 27 '08 #4
FileSystemWatcher is very convenient but far from perfect. Some events will
lost espectially with lot of actions simultaneously. You will need you timer
to keep clean job.

"Andrew Cooper" wrote:
Thanks folks!

I knew there had to be a way to do that without a timer.
FileSystemWatcher is exactly what I need.

Also, Patrice, unfortunately I can't change how these programs
communicate. The other program is proprietary and modifying this file
is the most it will do to help me out. I'd much rather use a socket
connection or something to communicate but... alas!

Andrew

Andrew Cooper wrote:
I've got an application that I'm modifying and the client needs it to
watch a particular file and then do some stuff when that file gets
modified. For example, let's say the file is C:\Test.dat and that it
looks like this...

AcctNum, 500
SomeValue, 4500

Periodically there is another program that changes the Test.dat file
values. The application I'm modifying needs to detect that the Test.dat
file has been modified, read it and then do some stuff with the values.
This isn't supder difficult. I can just place a timer in the
application that checks the File.GetLastWriteTime method for Test.dat
and then acts appropriately. However, that seems kind of inefficient.
Is there an event or something that I can latch onto to accomplish the
same thing without having to constantly fire a timer off?

Thanks for any help.

Andrew Cooper
Jun 27 '08 #5
The system isn't really that busy. The file is only being change every
great once in a while so I doubt I'll run into problems with it changing
too fast and missing something. But I will keep it in mind if things
start behaving strangely.

Andrew

intiratr wrote:
FileSystemWatcher is very convenient but far from perfect. Some events will
lost espectially with lot of actions simultaneously. You will need you timer
to keep clean job.
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1607
by: Benjamin D. LeMasurier | last post by:
Hey everyone, Is there a way to "watch" a file for changes? I know I could poll the file every few seconds and check to see if the buffer has changed but is there a cleaner way? thanks! Ben
8
2197
by: Christopher Harrison | last post by:
I would like to, cleanly, watch a flat file for changes (updates and the like). The file will be altered by another program... I found some example code (which actually didn't compile) on Google,...
6
5934
by: Ajay Pal Singh | last post by:
Hi, I am creating a web service, which needs to take some actions based on the config file. I need a way to listen the changes as they occur in the config file so that the service can take...
3
1478
by: Luis Esteban Valencia Muñoz | last post by:
Hi everyone, I created a VB.NET application that looks at a folder in my local system from which I can read the file, enter data into the database and delete the file. I am using the filewatcher...
2
1104
by: paul | last post by:
Watching connections to your computer. Can some one tell where to start. I want to write some code to be alerted when some one connect to my computer and browses/copies/changes files or...
4
1109
by: John Dann | last post by:
I need to watch a specific file that updates at irregular intervals and raise an event when an update happens (ie file date/time stamp changes). I had heard that there is a native method in .Net...
0
798
by: John Dann | last post by:
I'm using the FileSystemWatcher with NotifyFilters.LastWrite set. This works fine during the same day but fails to fire its event for changes in the monitored file after midnight, ie into the next...
8
1960
by: Gordon Airporte | last post by:
I'm trying to find a way to take a file that another program has opened and writes to periodically, open it simultaneously in Python, and automatically update some of my objects in Python when the...
14
1133
by: Zed A. Shaw | last post by:
Hi Everyone, Just putting out an announcement that I've released a new version of Vellum numbered 0.16. This version should be ready for people to use as not much of the internal structure has...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.