You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am developing a tool for my company which analyses every USB device plugged to the system and if it doesn't fulfill some criteria , it is ejected automatically.
Doing some search on internet I ended with two little projects which do exactly what I need.
For ejecting a USB drive, the code from your site ;)
I just integrated both in a single .NET solution and I simply add an eject command every time I plugged a new USB device.
private void OnDriveArrived(object sender, DriveDetectorEventArgs e)
{
// Report the event in the listbox.
// e.Drive is the drive letter for the device which just arrived, e.g. "E:\\"
string s = "Drive arrived " + e.Drive;
listBox1.Items.Add(s);
VolumeDeviceClass volumes = new VolumeDeviceClass();
foreach (Volume vol in volumes.Devices) {
if (vol.LogicalDrive.Equals(e.Drive.Replace("\\","")))
{
listBox1.Items.Add("Attempting to eject drive: " + e.Drive);
vol.Eject(false);
listBox1.Items.Add("Done ejecting drive.");
break;
}
}
}
My problem appears when I plug 2 devices at the same time, the code only manages to eject the first device. It seems like that the ejection of the first USB drive also remove the "onArrrived" event of the second drive. As a result, the second drive keeps accessible.
Any idea of what might be happening?
I attach the .net solution in case you want to reproduce the issue.
I am developing a tool for my company which analyses every USB device plugged to the system and if it doesn't fulfill some criteria , it is ejected automatically.
Doing some search on internet I ended with two little projects which do exactly what I need.
I just integrated both in a single .NET solution and I simply add an eject command every time I plugged a new USB device.
My problem appears when I plug 2 devices at the same time, the code only manages to eject the first device. It seems like that the ejection of the first USB drive also remove the "onArrrived" event of the second drive. As a result, the second drive keeps accessible.
Any idea of what might be happening?
I attach the .net solution in case you want to reproduce the issue.
SimpleDetector.zip
Many thanks in advance.
Jose
The text was updated successfully, but these errors were encountered: