473,597 Members | 2,113 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.GetLastWri teTime 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 1184
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.GetLastWri teTime 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 FileSystemWatch er 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.GetLastWri teTime 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.
FileSystemWatch er 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.GetLastWri teTime 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
FileSystemWatch er 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.
FileSystemWatch er 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.GetLastWri teTime 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:
FileSystemWatch er 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
1615
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
2218
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, but it essentially does it the way I would have in the first place (i.e. sets up a loop and gets the file's attributes each iteration, comparing to the previous instance). This seems kind of cludgy to me: is there a better way? Thank you :)...
6
5942
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 appropriate action for the cahnges. Is there any way i can implement this. Thanks, Ajay
3
1483
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 class.. However I need to do the same with ASP.NET. I want this application to be running all the time and I want the changes to be reflected on the ASP.NET page i.e the graphs on the ASP.NET page reflect the data that is being entered in the...
2
1110
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 directories. I know you can see them using Windows Mangement services, but I want some real time monitoring.
4
1122
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 for doing just this but can't see it. Anyone able to help please? JGD
0
807
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 day, until the program is reset when it carries on perfectly happily again. I can't see why this should happen, the file's datetime stamp obviously continues to change irrespective of whether it's the same day or the next day. Is there some...
8
1965
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 file is written to. I can open the file and manually readlines() from it to keep up to date, it's the automatic part I'm having trouble with. This is on Windows.
14
1144
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 changed in a great many commits and it contains all the latest bug fixes. It also has the beginning of an extensive PDF document describing how to use it. This is still an in-progress work, so it has grammar mistakes and spelling errors, but...
0
7886
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8035
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3886
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.