how to see if a drive is ready on Framework ver 1.1

  • Thread starter Derick Beckwith
  • Start date
D

Derick Beckwith

Hello,

How would I quickly determine if a logical disk drive is ready to use?
I am developing for ver 1.1 so the DriveInfo class is not available to me.
The method I am currently using seems to be popular:

// force exception if drive not ready
DirectoryInfo dir = new DirectoryInfo(rootDirectoryName);
dir.GetDirectories();

Using this code and just catching the exception in an empty block seems to
work ok
if you only have 1 or 2 drives that are not ready (ie empty floppy and CD
drives). However, I have notice that it is not the fastest way since
throwing exceptions slows down the app. Is there a way to check each drive
without throwing an exception each time one is not ready? Is there a Win32
function (example code would be great) that I can use through interop?

Thanks,
Derick
 
N

Nicholas Paldino [.NET/C# MVP]

Derick,

How often are you performing the operation on a drive that you are
trying to save information on? If this was being executed repeatedly, then
I would say it's a concern, but if it's something that's done as the result
of a user action, then I say throw the exception.

You can always use an API function to get the information you need as
well, if you really want to avoid the try/catch/exception route.

Hope this helps.
 
D

Derick Beckwith

Thanks for the quick reply Nicholas.
How often are you performing the operation on a drive that you are
trying to save information on?

I am using the Environment.GetLogicalDrives(); function and then iterating
through the string array and checking each drive one at a time so I can add
the drives to a tree view control. The problem is that this is done before
the form loads and also done 2 times, once for each tree view control on the
form. So it takes several seconds for the form to become visible (about 6
exceptions are thrown and caught). I will add another method to get the
logical drives that are ready so I only have to do this one time and will
also try using the static method Directory.Exists.

Thanks again,
Derick
 
N

Nicholas Paldino [.NET/C# MVP]

Derick,

Hmm, six seconds is a bit much to ask for a control to load up. I would
look at an API function to do this, I'm sure you can cut that down some.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top