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.