How to wait for CD to Mount

freak99

New member
Joined
Dec 20, 2003
Messages
2
Im writing a program in VB.Net that calls another command line program that mounts CD images into a virtual CD (D-Tools Daemon). My program then uses the mounted image like a regular CD.

The problem is that Daemon returns from the command line before it is actually done mounting the CD. It takes about 5-10 seconds. And in the next few lines of code when I go to read from the mounted image I get a System.IO.IOException saying that the drive is not ready.

How can I check to see if the image is mounted before proceeding to read from it?

Im hoping there is some nice clean event-oriented way (AddHandler?) of doing this. Im still pretty new to VB.Net so a short example would be helpful.
 
First you would have to wait for the program to finish. That could be achieved using the process class, its Start and WaitForExit methods.
Code:
Dim p as Process = Process.Start("program path")
wait for the process to exit
p.WaitForExit()
As for waiting for an event indicating if the drive is ready, either Im unaware of that or it doesnt exist. FileSystemWatcher would be a great component but unfortunately it will rise an exception if the drive is not ready when you specify the path. One way you could do that is like this:
Code:
Dim p as Process = Process.Start("program path")
wait for the process to exit
p.WaitForExit()
Do While Not System.IO.Directory.Exists("Virtual CD drive letter:\")
     Application.DoEvents()
Loop
When the drive will be ready so will be the Exists method return True thus getting you out of the loop.
 
Back
Top