private void DriveComboBox_SelectedIndexChanged(object sender, EventArgs e) { LogicalDrive chosenLogicalDrive = logicalDrives[DriveComboBox.SelectedIndex]; subThread = new Thread(() => getLogicalDriveSubDirectories(chosenLogicalDrive)); subThread.Start(); }
public void getLogicalDriveSubDirectories(LogicalDrive chosenLogicalDrive) { Thread t = new Thread(chosenLogicalDrive.GetDirectories); chosenLogicalDrive.SubDirectoriesDiscoveredEvent -= onLogicalDriverSubDirectoriesDiscovered; chosenLogicalDrive.SubDirectoriesDiscoveredEvent += onLogicalDriverSubDirectoriesDiscovered; t.Start(); t.Join(); }
// Обработчик события получения списка папок на устройстве public void onLogicalDriverSubDirectoriesDiscovered(LogicalDrive logicalDrive) { DirectoryListBox.BeginInvoke(new Action(() => { DirectoryListBox.Items.Clear(); foreach (Directory directory in logicalDrive.SubDirectories) { DirectoryListBox.Items.Add(directory.DirName); } })); }
private void Form1_Load(object sender, EventArgs e) { // Получаем названия (пути) подключенных устройств string[] logicalDrivesNames = Environment.GetLogicalDrives(); logicalDrives = new LogicalDrive[logicalDrivesNames.Length]; // Заполняем массив с устройствами for (int i = 0, numOfLogicalDrives = logicalDrivesNames.Length; i < numOfLogicalDrives; ++i) { logicalDrives[i] = new LogicalDrive(logicalDrivesNames[i]); } // Добавляем устройства в КомбоБокс DriveComboBox.Items.AddRange(logicalDrivesNames); }