0

Running latest Visual Studio Community on Win10 20H2.

I'm working on a C# winforms desktop app which monitors some local drive properties and displays a status message. If a drive selected for monitoring is missing an error message is displayed providing the user an option to plugin missing drives than rerun analysis.

System.IO.DriveInfo is used to detect available drives. Data is saved/accessed with CSV files. For testing I unplug/plug-in a USB drive.

When I plug-in the "missing" drive and rerun the scan/analysis (with new instances of all contributing methods) the DriveInfo scan is not picking up the change even though Windows Explorer/file manager is detecting the change.

If I terminate and than restart the debug session the change is picked up.

Is this behavior due to VS keeping some sort of working cache during a debug session or due to my not having figured out how to Dispose of old instances properly (or something else entirely)?

Thanx in advance for your help.

Art Hansen
  • 57
  • 8
  • I don't think VS itself maintains caches. The debug process which supervises the execution of the project, is itself only a process in memory, a module separate from VS which controls the execution and which dispatches things toward VS in case of step-by-step or exceptions, as I know a little. Thus if something is cached in memory or disk, you should rather look at profilers and other specific and independent VS extensions, as well as the OS itself. However I have no idea how modern debuggers handle debugging symbols... but I don't think such a thing is related to what you called "*cache*". –  Aug 14 '21 at 12:44
  • So, if you add this: `listBox1.DisplayMember = "Name"; listBox1.DataSource = DriveInfo.GetDrives();` to a `Button.Click` handler and add a ListBox to your Form, you don't see the list content change when you add/remove an USB drive and click the Button? -- DriveInfo doesn't *detect*, it just calls `Directory.GetLogicalDrives()` and returns a new collection. – Jimi Aug 14 '21 at 12:47
  • Otherwise Visual Studio save all project and IDE special settings (debug or release selected, opened files, toolboxes location...) in the `.vs` folder using a sqlite database and various files. But these things are not related to the execution of the project itself. –  Aug 14 '21 at 12:48
  • If you actually want to detect and get a notification when an USB device is added or removed from the System, this is one way to do it: [How do I get information about recently connected USB device?](https://stackoverflow.com/a/54298316/7444103) – Jimi Aug 14 '21 at 13:05
  • 1
    @Jimi the listbox updates as expected so obviously DriveInfo is accurately getting realtime info - I'll look elsewhere. Thx. – Art Hansen Aug 14 '21 at 16:23

0 Answers0