开发者

System.IO.DriveInfo.GetDrives() hangs with disconnected network drives

开发者 https://www.devze.com 2022-12-09 19:32 出处:网络
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.

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 m开发者_JAVA百科y 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号