Bonjour à tous,
Je suis nouveau en programmation c# donc excusez-moi par avance si ma question parait "débile"
En fait je voudrais faire un Parallel.ForEach de ça :
Du coup j'ai écrit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 private void startButton_Click(object sender, RoutedEventArgs e) { logbox.AppendText("Initialization ... \n"); logbox.AppendText("----------------------------------------------\n"); ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\"+System.Windows.Forms.SystemInformation.ComputerName.ToString()+ "\\root\\cimv2", "SELECT * FROM Win32_USBControllerDevice"); foreach (ManagementObject wmi_USBDevice in searcher.Get()) { String[] devices = wmi_USBDevice["Dependent"].ToString().Split('='); ManagementObjectSearcher searcherDevice = new ManagementObjectSearcher("\\\\" + System.Windows.Forms.SystemInformation.ComputerName.ToString() + "\\root\\cimv2", "SELECT * FROM Win32_PnpEntity Where DeviceID=" + devices[1]); foreach (ManagementObject wmi_USB in searcherDevice.Get()) { if (wmi_USB["Description"].ToString() == "MY USB KEY") { allusbdongle = wmi_USB["Description"].ToString() + "PORT :" + wmi_USB["DeviceID"].ToString(); } } } }
mais bien sur ça ne marche pas et je ne comprend pas pourquoi...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 private void startButton_Click(object sender, RoutedEventArgs e) { logbox.AppendText("Initialization ... \n"); logbox.AppendText("----------------------------------------------\n"); ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\"+System.Windows.Forms.SystemInformation.ComputerName.ToString()+ "\\root\\cimv2", "SELECT * FROM Win32_USBControllerDevice"); Parallel.ForEach(searcher.Get(), wmi_USB => { String[] devices = wmi_USBDevice["Dependent"].ToString().Split('='); ManagementObjectSearcher searcherDevice = new ManagementObjectSearcher("\\\\" + System.Windows.Forms.SystemInformation.ComputerName.ToString() + "\\root\\cimv2", "SELECT * FROM Win32_PnpEntity Where DeviceID=" + devices[1]); foreach (ManagementObject wmi_USB in searcherDevice.Get()) { if (wmi_USB["Description"].ToString() == "MY USB KEY") { allusbdongle = wmi_USB["Description"].ToString() + "PORT :" + wmi_USB["DeviceID"].ToString(); } } }); }
Quelqu'un pourrait il m'éclairer ??
Merci à vous : )
Partager