Error while ejecting USB devices

muskaan

New member
Joined
Dec 10, 2009
Messages
2
Programming Experience
1-3
Hi

I am having trouble ejecting the USB device. It gives an error saying " The device cannot be stopped right now. Try stopping the device later"

To duplicate the problem, I created a very simple application with two forms.

Form 1 has a button to the Form 2.

Public Class Form1

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim f As New Form2

Try
f.ShowDialog()
Finally
f.Dispose()
f = Nothing
End Try

End Sub


End Class

Form 2 has a button to the OpenFileDialog, in which we select a file and click open, and close the Form2. Now I am on Form 1 and I want to eject the USB drive. But I am unable to do that.

Public Class Form2

Dim openfiledialog1 As OpenFileDialog

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

OpenFileDialog1.ShowDialog()

End Sub

Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

openfiledialog1.Dispose()
openfiledialog1 = Nothing

End Sub

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

openfiledialog1 = New OpenFileDialog

End Sub

End Class

To me, it seems that the OpenFileDialog or form is holding a lock to one of the folders. All I want to do is, eject the USB drive using "safely remove hardware" without getting the busy message, while I am on Form2. Could anyone help me with this.

Thanks
 
VB.NET:
Public Class Form2

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Using openfiledialog1 As new OpenFileDialog
        OpenFileDialog1.ShowDialog()
    End Using

End Sub

End Class
 
Hi,

i tried exactly what you posted. It also gives the same error after i select a file from the openFileDialog and click open and exit form2. Now I am on Form1 , i try to eject the device get an error "The device cannot be stopped right now. Try stopping the device later".

Could you suggest me something by which i can eliminate the busy message.

Thanks
 
Back
Top