Debugging: runtime break on file change? (window)

Is it possible to interrupt at runtime when a particular file has been modified?

T. Track the file and enter the debugger after making changes to it.

This is for a windows application ... is this possible in visual studio or windbg?

edit: I should have mentioned that this is for a Win32 application.

+3
source share
2 answers

you can use the System.IO.FileSystemWatcher class.

FileSystemWatcher watcher = = new FileSystemWatcher();
watcher.Filter = @"myFile.ini";
watcher.Changed += new FileSystemEventHandler(watcher_Changed);

and then you implement a delegate of type FileSystemEventHandler:

static void watcher_Changed(object sender, FileSystemArgs e)
{
    Console.WriteLine("File {0} has changed.", e.FullPath );
}

every time the file you select in the filter changes, you get a warning (you can use the Debug or Trace class to display data). In addition, the FileSystemWatcher class has more events (renamed, deleted, created).

+2

, .NET, System.IO. FileSystemWatcher - , .

FileSystemWatcher watcher = new FileSystemWatcher("c:filename.txt");
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
// 
void watcher_Changed(object sender, FileSystemEventArgs e)
{
    // put a breakpoint here
}
0

Source: https://habr.com/ru/post/1698160/


All Articles