コードで DriveInfo.GetDrives() メソッドを使用して、指定したコンピューターで利用可能で準備ができているすべてのリムーバブル ドライブをコンボボックスに入力します。3 台のテスト コンピューターでは問題なく動作しますが、1 台のコンピューターでは、ユーザーがコンボ ボックス (およびコンストラクターの GetDrives) を含むウィンドウを開くボタンをクリックすると、ウィンドウが開くまでに数秒かかります。
コンピューターは Windows 7 を実行しており、注意すべき唯一のことは、RAID セットアップがあることです。
開くと、何らかの理由で開いたときにハングするだけです。MSDN のドキュメントには何のヘルプも見つかりませんでしたし、オンラインでも同様のケースは見つかりませんでした。同様の問題を経験したことがある場合や、提案があれば教えてください。
プロジェクトから DriveInfo を使用するウィンドウを抽出し、テスト アプリケーションを作成しました。背後にあるコードは次のとおりです。
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<string> drivesTemp = new List<string>();
foreach (DriveInfo d in DriveInfo.GetDrives())
{
if (d.IsReady == true && d.DriveType == DriveType.Removable && d.DriveFormat == "FAT32")
{
drives.Items.Add(d.VolumeLabel + " (" + d.Name + ")");
drivesTemp.Add(d.Name);
count++;
}
}
driveNames = new string[count];
for (int i = 0; i < 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();
}
}