Note that there are some explanatory texts on larger screens.

plurals
  1. POC# DriveInfo.GetDrives () slow on select computer
    text
    copied!<p>I use the DriveInfo.GetDrives() method in my code to populate a combobox with all available and ready removable drives on my specified computer. It works great on three test computers, but on a single computer when the user clicks the button that opens the window with the combo box in it (and the GetDrives in the constructor) it takes a good few seconds before the window opens up.</p> <p>The computer is running Windows 7 and the only things to note would be it has a RAID setup.</p> <p>Once open it is responsive it just hangs when opening for some reason. I couldn't find anything of help on the MSDN documentation and I found no similar cases online. Please let me know if you have had any experiences with similar issues or any suggestions.</p> <p>I extracted the window that used the DriveInfo from my project and built a test application. The code behind is below:</p> <pre><code>public partial class MainWindow : Window { //Instance variables used in class and refrenced in 'get' methods int count; string[] driveNames; public MainWindow() //Constructor { InitializeComponent(); getInfo(); //Populate instance vars } public string[] getRemovableDrives() //Returns array of drive letters for removable drives in computer { return driveNames; } public int getRemovableDrivesCount() //Returns number of removable drives in computer { return count; } private void getInfo() //Run once to get information about removable drives on computer and store into instance vars { count = 0; List&lt;string&gt; drivesTemp = new List&lt;string&gt;(); foreach (DriveInfo d in DriveInfo.GetDrives()) { if (d.IsReady == true &amp;&amp; d.DriveType == DriveType.Removable &amp;&amp; d.DriveFormat == "FAT32") { drives.Items.Add(d.VolumeLabel + " (" + d.Name + ")"); drivesTemp.Add(d.Name); count++; } } driveNames = new string[count]; for (int i = 0; i &lt; count; i++) { driveNames[i] = drivesTemp[i]; } } private void Window_Loaded(object sender, RoutedEventArgs e) //Selects first available drive in drop down box { drives.SelectedIndex = drives.Items.Count - 1; } private void format_Click(object sender, RoutedEventArgs e) //Attempts to format drive { string drive = driveNames[drives.SelectedIndex]; try { Directory.CreateDirectory(drive + "LOOKOUT.SD"); Directory.CreateDirectory(drive + "LOOKOUT.SD\\CONFIG"); Directory.CreateDirectory(drive + "LOOKOUT.SD\\HISTORY"); Directory.CreateDirectory(drive + "LOOKOUT.SD\\TEST"); Directory.CreateDirectory(drive + "LOOKOUT.SD\\UPDATES"); Directory.CreateDirectory(drive + "LOOKOUT.SD\\VPROMPTS"); MessageBox.Show("Format complete, your removable device is now ready to use.", "Format Successful", MessageBoxButton.OK, MessageBoxImage.Information); } catch { MessageBox.Show("Your removable device has failed to format correctly.", "Format Failure", MessageBoxButton.OK, MessageBoxImage.Exclamation); } Close(); } private void cancel_Click(object sender, RoutedEventArgs e) //Closes window without formatting { Close(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload