Is there any way of having a VS debug session break when a specific file is read from or written to?
In this case I'd want to use it as an exploratory tool -- assume I don't know where in a large codebase this file is being accessed from, or where the filename is being set -- it might be picked up from deep in some large scale config.
Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.
Conditional breakpoints allow you to break inside a code block when a defined expression evaluates to true. Conditional breakpoints highlight as orange instead of blue. Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression.
You can disable all breakpoints in one of the following ways: On the Debug menu, click Disable All Breakpoints. On the toolbar of the Breakpoints window, click the Disable All Breakpoints button.
What I would do is just quickly hack up a static class that uses the FileSystemWatcher class to listen to file create/changed events, and put a breakpoint in the event callback, or put a call to System.Diagnostics.Debugger.Break there.
Then, when it breaks, switch to the Threads window and try to locate the thread and the piece of code that did the actual file-access.
If you need to use this a lot, have this class maintain a list of specific file names you want to break on, and expose two public static methods: to Start and Stop listening to changes in a specific file.
Also, if you have VS2010 Ultimate you could simply search through the list of File Created events in the IntelliTrace events log.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With