Reputation: 4501
I would like to be notified in my C# application when another process makes changes to a particular textfile.
The reason for this is that I launch a 3rd party tool from my application in order to retrieve some information about a device. this tool saves the current state of the device into an ini file. This takes some undetermined time, but I want to react and read the state information as soon as it's available.
How can I do this?
Upvotes: 3
Views: 667
Reputation: 152
You could use the System.IO.FileSystemWatcher class. Something like this:
string fileToWatch = @"C:\MyFile.txt";
fileSystemWatcher = new FileSystemWatcher(fileToWatch);
void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
Debug.WriteLine(e.Name + " has changed");
}
Upvotes: 3
Reputation: 8560
You can monitor file changes using System.IO.FileSystemWatcher
Also, see Notification when a file changes? for more info.
Upvotes: 2