471,350 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Unable to detect a file change with FileSystemWatcher


I have some problems to detect when a file is changed by another application
(the file is changed several times by the application). Sometimes, it is
correctly detected, sometimes not. I maybe expect an access problem. Can it
be? And how to solve it? Below is a part of my code (written in C#). Is there
anybody who can help me?

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "C:\\TEMP;
watcher.NotifyFilter = NotifyFilters.LastWrite ;
watcher.Filter = "file1.ini";
mszStatus = "Start";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
method.mfStart(); // This will start the external program

// Wait so that the method is completed.
while (String.Compare(mszStatus,"Stop") != 0)


// Define the event handlers.
private void OnChanged(object source, FileSystemEventArgs e)
.... // Look in the file for a specific string
if (....) // If string = finished
mszStatus = "Stop";

Jul 22 '05 #1
0 1257

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Vinny | last post: by
12 posts views Thread by Anders Eriksson | last post: by
3 posts views Thread by Kenneth H. Brannigan | last post: by
4 posts views Thread by intrepid_dw | last post: by
reply views Thread by deerchao | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.