2

I am writing a file manager in .NET 3.5. At startup, the application must enumerate available drives. I am using DriveInfo.GetDrives to do that.

Unfortunately my users lamented that, when they have disconnected network drives, the application took about 30 seconds to start.

I discovered that the GetDrives() function hangs for many seconds when you have a disconnected network drive. And the UI freezes. This happens at startup, and each time I attach a new drive.

To sum up, I need a way to enumerate available drives which returns immediately, even though there are disconnected network drives. Thanks for any help.

Additional informations:

  1. I did some test with WMI, and the same problem arises. The WMI query returns after 15 seconds or so.

  2. I have also considered moving the call to DriveInfo to a separate thread. This would solve the problem of not blocking the user interface; but it would mean that, when the user attaches a new drive, the drive icon would only appear after 15 seconds. That is not ideal.

Thank you very much for any help.

seguso
  • 2,024
  • 2
  • 18
  • 20
  • I don't see how solution 2 would cause the 15 second delay for new drives. I assume you call GetDrives() again, because you can't get the affected drive letter from your notification mechanism? If you do, you can trivially calculate the new set of drives without an expensive GetDrives() call. – MSalters Oct 23 '09 at 10:12
  • Exactly so: when the user attaches a USB drive, I receive the messages WM_DEVICECHANGE + DBT_DEVICEARRIVAL, but I can't see how to get the letter of the newly attached drive, so I call GetDrives() again. You say I can avoid this, but I can't see how. Could you please explain? Thanks – seguso Oct 23 '09 at 10:19

1 Answers1

0

I fear that there isno way to avoid the blocking. It is due to network/file timeouts in Windows API.

PVitt
  • 11,500
  • 5
  • 51
  • 85