Hi Peter,

Don't know if this would help, but rather than using this bit:
drive.RootDirectory.ToString().Substring(0,1)

Perhaps if you instead iterated Directory.GetLogicalDrives and created the
DriveInfo's , eg:

private List<DriveInfo> GetDrivesOfType(DriveType driveType)

        {

            if(DrivesWithRemovableMedia == null)

            {

                DrivesWithRemovableMedia = new List<string>();

                String[] allDrives = Driectory.GetLogicalDrives();

 

                foreach (string driveName drive in allDrives)

                {
 
                   var drive = new DriveInfo(driveName);
                    if (drive.DriveType == driveType)

                        DrivesWithRemovableMedia.Add(driveName);

                } 

            }

            var selectedDrives = new List<DriveInfo>();

            foreach(string driveDesignation in DrivesWithRemovableMedia)

            {

                var drive = new DriveInfo(driveDesignation);

                if(drive.IsReady)

                {

                    selectedDrives.Add(drive);

                    // we only want the first ready CD/DVD drive

                    break;

                }

            }


|-----Original Message-----
|From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of Maddin, Peter
|Sent: Tuesday, 18 May 2010 2:43 PM
|To: ozDotNet
|Subject: RE: DriveInfo.GetDrives() not returning
|
|Thanks Mitch and David
|
|
|
|I had thought of that as well.
|
|I have a USB CD Rom drive that I plugged in.
|
|
|
|I get exactly the same problem with the USB CD Rom drive.
|
|
|
|I can use Windows explorer to navigate to the drive in question and open a
file
|present on the media (I am only processing CSV files).
|
|It does not appear to be the drive (or drives in my case) as I can gain
access to
|them and the files on the media after my app has hung.
|
|
|
|I tried changing the code to this
|
|
|
|private List<DriveInfo> GetDrivesOfType(DriveType driveType)
|
|        {
|
|            if(DrivesWithRemovableMedia == null)
|
|            {
|
|                DrivesWithRemovableMedia = new List<string>();
|
|                DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|
|
|                foreach (DriveInfo drive in allDrives)
|
|                {
|
|                    if (drive.DriveType == driveType)
|
|
|DrivesWithRemovableMedia.Add(drive.RootDirectory.ToString().Substring(0,1))
;
|
|                }
|
|            }
|
|            var selectedDrives = new List<DriveInfo>();
|
|            foreach(string driveDesignation in DrivesWithRemovableMedia)
|
|            {
|
|                var drive = new DriveInfo(driveDesignation);
|
|                if(drive.IsReady)
|
|                {
|
|                    selectedDrives.Add(drive);
|
|                    // we only want the first ready CD/DVD drive
|
|                    break;
|
|                }
|
|            }
|
|
|
|It hangs on var drive = new DriveInfo(driveDesignation); the second time
the
|method is called.
|
|
|
|If I stop debugging I get this dialog.
|
|
|
|
|
|
|
|
|
|If I use the 'Stop Now', I can continue to execute the code again (only to
get  the
|same problem).
|
|I cannot rebuild as there are file locks on the files (dll, exe, pdb etc).
|
|
|
|To continue I have to reboot.
|
|The actual application goes rogue (unkillable) which is a new one for me on
|windows (XP Pro SP3).
|
|I use to see zombies on various Unix systems every now and then (most of
them
|of my own making) but not so with windows.
|
|
|
|I will test the app on another machine to see if my own machine has started
to
|hate me (its not paranoia if they really are out to get you).
|
|
|
|I will try putting the entire thing in another thread to see if that helps.
|
|
|
|Regards Peter Maddin
|Applications Development Officer
|PathWest Laboratory Medicine WA
|Phone : +618 9473 3944
|Fax : +618 9473 3982
|E-Mail : [email protected]
|The contents of this e-mail transmission outside of the WAGHS network are
|intended solely for the named recipient's), may be confidential, and may be
|privileged or otherwise protected from disclosure in the public interest.
The
|use, reproduction, disclosure or distribution of the contents of this
e-mail
|transmission by any person other than the named recipient(s) is prohibited.
If
|you are not a named recipient please notify the sender immediately.
|
|
|
|
|
|
|
|
|
|From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of Mitch Wheat
|Sent: Tuesday, 18 May 2010 12:23 PM
|To: 'ozDotNet'
|Subject: RE: DriveInfo.GetDrives() not returning
|
|
|
|Perhaps there is something wrong with your drive?
|
|
|
|Just successfully  tried the code you posted under similar conditions to
those
|you described.
|
|
|
|Mitch
|
|
|
|From: [email protected] [mailto:ozdotnet-
|[email protected]] On Behalf Of Maddin, Peter
|Sent: Tuesday, 18 May 2010 11:53 AM
|To: [email protected]
|Subject: DriveInfo.GetDrives() not returning
|
|
|
|I am writing a simple application where users can import data from a file
on a
|CD/DVD.
|
|
|
|To get a list of ready CD/DVD drives I am using this code
|
|
|
|  /// <summary>
|
|        /// Returns drives of specified type ~ and specified status.
|
|        /// </summary>
|
|        /// <param name="driveType">The type of drive one is primarily
|interested in</param>
|
|        /// <returns>
|
|        /// Drive designation of the first available drive for the
specified DriveType
|or if none are ready, the
|
|        /// drive designation of the drive where this assembly is being
executed.
|
|        /// </returns>
|
|        private List<DriveInfo> GetDrivesOfType(DriveType driveType)
|
|        {
|
|            DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|            var selectedDrives = new List<DriveInfo>();
|
|            // Look for first CD/DVD drive that is ready
|
|            foreach (DriveInfo drive in allDrives)
|
|            {
|
|                if (drive.DriveType == driveType)
|
|                    if (drive.IsReady)
|
|                    {
|
|                        selectedDrives.Add(drive);
|
|                        // we only want the first ready CD/DVD drive
|
|                        break;
|
|                    }
|
|            }
|
|            // if there is no ready CD/DVD drive then get the drive info
for
|
|            // the drive where this assembly is executing.
|
|            if (selectedDrives.Count == 0)
|
|                selectedDrives.Add(new
|DriveInfo(Path.GetPathRoot(Assembly.GetExecutingAssembly().Location))); ;
|
|
|
|            return selectedDrives;
|
|        }
|
|
|
|When I first use this method, it works fine.
|
|When a user opens the drive, removes the CD/DVD, closes it again and waits
|for it to register the presence of new media, then as part of the process
to read
|in a new file
|
|the method is called again.
|
|
|
|When called a second time, it hangs on DriveInfo[] allDrives =
|DriveInfo.GetDrives();
|
|
|
|The actual application turn rogue. You cannot kill it off in windows task
|manager.
|
|If debugging in Vs2008, the debugger eventually detaches the process and
one
|can start again.
|
|
|
|Is there any known reason why this sort of behaviour would occur?
|
|
|
|I moved DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|So its called only once, but then it hangs on
|
|if (drive.IsReady)
|
|
|
|I can't seem to do anything to address this problem.
|
|The DriveInfo class does not have anything that I can see t
|
|One solution I have had is to run this in a separate thread and it if does
not
|respond, kill the thread.
|
|Ok that may deal with the hang-up but it still does not enable the user to
open
|and process on the files on the CD/DVD media.
|
|
|
|I have googled on this and seen other with similar issues. One suggestion
is that
|the DriveInfo[] allDrives = DriveInfo.GetDrives();
|
|Will usually return after 30 seconds but may take up to 3 minutes. In my
case it
|does not return at all.
|
|
|
|I am targeting .NET 3.5. Is it a framework problem, driver problem, some
other
|problem?
|
|Could it just be the machine I am using?
|
|Anyone else experienced this sort of issue?
|
|
|
|
|
|Regards Peter Maddin
|Applications Development Officer
|PathWest Laboratory Medicine WA
|Phone : +618 9473 3944
|Fax : +618 9473 3982
|E-Mail : [email protected]
|The contents of this e-mail transmission outside of the WAGHS network are
|intended solely for the named recipient's), may be confidential, and may be
|privileged or otherwise protected from disclosure in the public interest.
The
|use, reproduction, disclosure or distribution of the contents of this
e-mail
|transmission by any person other than the named recipient(s) is prohibited.
If
|you are not a named recipient please notify the sender immediately.
|
|
|
|
|
|
|
|
|
|


Reply via email to