Ошибка "Устройство не готово" на DriveInfo.DriveFormat

У меня есть этот метод, который извлекает информацию о съемных устройствах, которые являются NTFS:

    private void getdriverinfo()
    {
        // get the usb flash driver
        foreach (DriveInfo driveInfo in DriveInfo.GetDrives())
        {
            if (driveInfo.DriveType == DriveType.Removable && driveInfo.DriveFormat.Equals("NTFS"))
            {
                comboBox1.Items.Add(driveInfo.Name);
            }
        }
        if (comboBox1.Items.Count == 0)
        {
            MessageBox.Show("No Removable Device Found , please plug in the USB drive and make sure it is in NTFS format and retry", "No Device Found!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else if (comboBox1.Items.Count == 1)
        {
            comboBox1.Text = comboBox1.Items[0].ToString();
        }
        else
        {
            MessageBox.Show(comboBox1.Items.Count + " Removable Devices were found , please choose the device you want to protect");
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // get the usb flash driver
        getdriverinfo();       
    }

Эта ошибка возникает:

System.IO.IOException: устройство не готово.

в System.IO .__ Error.WinIOError (Int32 errorCode, String может бытьFullPath)

в System.IO .__ Error.WinIODriveError (String driveName, Int32 errorCode)

в System.IO.DriveInfo.get_DriveFormat ()

в USB_Data_Protector.Form1.getdriverinfo ()

Это отлично работает на моем ноутбуке без ошибок. Эта ошибка отображается при запуске на виртуальном компьютере или другом компьютере.


person R.Vector    schedule 25.01.2012    source источник


Ответы (1)


Можете ли вы проверить следующее, прежде чем получить доступ к DriveFormat? Свойство IsReady

driveInfo.IsReady
person chandmk    schedule 25.01.2012
comment
Вау, это сработало, но почему? может быть, потому что нужно было время, чтобы быть готовым, или как? - person R.Vector; 25.01.2012
comment
добавил соответствующую ссылку на это свойство - person chandmk; 25.01.2012