IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

Parallel.ForEach petit soucis


Sujet :

C#

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 9
    Points : 6
    Points
    6
    Par défaut Parallel.ForEach petit soucis
    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 :

    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();
                        }
                    }
                }
     
            }
    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");
                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();
                        }
                    }
                });
     
            }
    mais bien sur ça ne marche pas et je ne comprend pas pourquoi...

    Quelqu'un pourrait il m'éclairer ??

    Merci à vous : )

  2. #2
    Modérateur
    Avatar de DotNetMatt
    Homme Profil pro
    CTO
    Inscrit en
    Février 2010
    Messages
    3 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : CTO
    Secteur : Finance

    Informations forums :
    Inscription : Février 2010
    Messages : 3 611
    Points : 9 742
    Points
    9 742
    Billets dans le blog
    3
    Par défaut
    Citation Envoyé par an.be Voir le message
    mais bien sur ça ne marche pas et je ne comprend pas pourquoi...

    Quelqu'un pourrait il m'éclairer ??
    Qu'est-ce qui ne marche pas ? Tu as un message d'erreur ? Si oui, merci de l'indiquer ça sera utile.

  3. #3
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 570
    Points
    3 570
    Par défaut
    Essaye :

    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    Parallel.ForEach(searcher.Get().Cast<ManagementObject>(), wmi_USBDevice =>
                {
                    String[] devices = wmi_USBDevice["Dependent"].ToString().Split('=');
     
                    ManagementObjectSearcher searcherDevice = new ManagementObjectSearcher("\\\\" + "Hangar18" + "\\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")
                        {
                            Debug.WriteLine(wmi_USB["Description"].ToString() + "PORT :" + wmi_USB["DeviceID"].ToString());
                        }
                    }
                });

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2011
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2011
    Messages : 9
    Points : 6
    Points
    6
    Par défaut
    Super!!

    ça marche nickel!!
    Merci beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Petit soucis pour se connecter à l'adsl
    Par Blowih dans le forum Réseau
    Réponses: 4
    Dernier message: 28/07/2004, 00h16
  2. petit soucy de fenetre cmd
    Par FeetloveR666 dans le forum Windows
    Réponses: 5
    Dernier message: 03/07/2004, 14h24
  3. petit soucis lors d'un LOAD DATA INFILE
    Par Jovial dans le forum SQL Procédural
    Réponses: 9
    Dernier message: 04/06/2004, 11h58
  4. Réponses: 6
    Dernier message: 21/01/2004, 13h25
  5. [DEBUTANT] petits soucis avec un prgm de chat
    Par LechucK dans le forum MFC
    Réponses: 8
    Dernier message: 19/01/2004, 16h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo