473,385 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
Apr 4 '07 #1
3 2344
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Derick Beckwith" <de*************@us.bosch.comwrote in message
news:ev**********@news4.fe.internet.bosch.com...
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


Apr 4 '07 #2

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
Apr 4 '07 #3
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Derick Beckwith" <de*************@us.bosch.comwrote in message
news:ev**********@news4.fe.internet.bosch.com...
>
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


Apr 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CMan | last post by:
Hi, We are currently trying to install .Net Framework v.1.1 on a server which already has v1.0. We are receiving the following error. Error 1704.An installation for Microsoft .NET Framework...
3
by: Just Me | last post by:
In code I check to see if the Floppy drive is ready and display it's state. But if the user inserts or removes a floppy disk I need an event or a Wndproc message to cause the code to display the...
0
by: Namratha Shah \(Nasha\) | last post by:
Type Library Importer : tlbImp This tool is used to convert the type library definitons found in COM components to .NET assembly. This tool works on the entire type library at the same time...
14
by: frostalicious | last post by:
Used VB.NET (on my client PC) to convert VB6 executable to .NET executable. Placed the .exe file on a network drive on my server. From client, ran .NET Wizards "Trust an Assembly" to make the...
3
by: programmer2004 | last post by:
Hi, I m .NET programmer. I am looking for a ready framework/code in vb.net, which contain all default menus, toolbar, so I only have to add my package related forms and coding. I am looking for...
3
by: Just Me | last post by:
I check to see if the Floppy drive is ready and display it's state. But if the user inserts or removes a floppy disk I need an event or Windproof message to cause the code to display the new...
10
by: Just Me | last post by:
If I periodically check to see if the floppy is ready, the drive will each time make a little noise. I've been up against this before and could never find a way to check to see if the floppy...
1
by: barbara_dave | last post by:
Hi all, I use GetLogicDrive to get all drives. when I use "for each.." loop searching each drive, I got error"A: drive not ready",... I want to seach some files which are in a drive, but I don't...
0
by: DosFreak | last post by:
I downloaded a file manager example with drives being listed and supposing E: was a cdrom, how do you that e: is ready? is there a win32 function to tell you that it is ready for reading without...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.