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

Windows Forms Discussion :

Thread execute au demarrage d'une fenetre


Sujet :

Windows Forms

  1. #21
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    je seche ...

  2. #22
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    Désolé, j'avais perdu de vue ce sujet.

    Avant de te répondre, pourrais-tu me résumer où tu en es en répondant aux questions suivantes :
    1. Tu as créé une classe qui englobe un Thread qui s'exécute pendant un certain temps afin de modifier la valeur d'une variable ?
    2. Où se trouve la variable modifiée ? Dans la classe de ta Form, dans la classe qui englobe le Thread ?
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  3. #23
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Salut

    Voici ma classe Thread :

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
    namespace AppThread
    {
        class theThread_Scan
        {
            private int iProg;
            private Thread ThreadScan;
     
            public theThread_Scan()
            {
                iProg = 0;
                this.ThreadScan = new Thread(new ThreadStart(ThreadLoop));
                this.ThreadScan.Name = "TEST_THREAD";            
            }
     
            public void Start()
            {
                this.ThreadScan.Start();
            }
     
            public bool isAlive()
            {
                return this.ThreadScan.IsAlive;
            }
     
            public void Stop()
            {
                this.ThreadScan.Abort();
            }
     
            private void ThreadLoop()
            {
                for (int i = 0; i < 100; i++)
                {
                    iProg++;
                    Thread.Sleep(10);
                }
            }
        }
    }
    et voici comment je le lance dans la fonction FRM_Prog_Shown d'une form :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    theThread_Scan aScan = new theThread_Scan();
    aScan.Start();
    La ou je n'ai pas compris c'est comment je recupere les infos (la variable iProg) dans la form pour par exemple les afficher en fonction de l'evolution dans un label ...

    @+

  4. #24
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    D'accord je comprend mieux.

    Ce que tu dois faire, c'est déclarer

    theThread_Scan aScan = new theThread_Scan();

    en global dans ta classe Form.

    En plus de celà, tu dois créer un timer qui générera son évènement Tick tous les x secondes. Le but de la méthode de ce timer est d'aller lire la valeur iProg (qu'il faudra mettre en public) de ton objet aScan pour ensuite l'afficher dans ta fenêtre. Tu peux aussi mettre une condition pour tester si IsAlive renvoie True.. si ce n'est pas le cas, tu arrêtes le timer.

    Si tu vois pas de quoi je parler concernant le Timer, dis le moi.
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  5. #25
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Merci

    Pas besoin d'utiliser delegate alors ?

  6. #26
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    En effet, dans ce cas ci, il n'y a pas besoin de delegate.
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  7. #27
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Citation Envoyé par Goldar
    En effet, dans ce cas ci, il n'y a pas besoin de delegate.

    Merci j'ai remarque un chti prob ... il n'y a pas l'evolution de la variable quand je l'affiche dans un label ... il passe directement a 100 ....

    Est ce que tu pourrais me dire, tout de meme, comment faire avec le deleguate ??


    thx @+

  8. #28
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    C'est normal que ça passe directement à 100.
    Tu as fait un Thread.Sleep de 10 milisecondes en pensant que c'était des secondes.

    Tu dois donc écrire :

    Pour attendre 10 secondes à chaque tour de boucle.
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  9. #29
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Citation Envoyé par Goldar
    C'est normal que ça passe directement à 100.
    Tu as fait un Thread.Sleep de 10 milisecondes en pensant que c'était des secondes.

    Tu dois donc écrire :

    Pour attendre 10 secondes à chaque tour de boucle.
    Meme en augmentant le sleep ... j'ai mis egalement une progressbar, la je vois bien la valeur augmente, par contre avec le label ca bouge pas ... 0 puis a la fin 100

  10. #30
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    Quel est ton code qui met à jour la valeur de ton label ?
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  11. #31
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Voila (de memoire)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    while (monThread.isAlive(){
       label.texte = monThread.getVal().toString();
       progbar.value = monThread.getVal();
    }

  12. #32
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    C'est même pas un problème d'affichage car je viens de tester un timer qui met à jour un label en incrémentant un nombre de une unité à chaque seconde et tout s'affiche correctement.

    J'avoue que ça va être difficile de t'aider plus si tu me dis qu'avec ton progressbar ça fonctionne.
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  13. #33
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Citation Envoyé par Goldar
    C'est même pas un problème d'affichage car je viens de tester un timer qui met à jour un label en incrémentant un nombre de une unité à chaque seconde et tout s'affiche correctement.

    J'avoue que ça va être difficile de t'aider plus si tu me dis qu'avec ton progressbar ça fonctionne.
    Je vais reessaye ce soir ... je te tient au courant ...

    Sinon tu pourrais pas m'expliquer comment faire le delelguate .. ca m'interesse ...

  14. #34
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    C'est vrai que mes explications ne sont pas toujours très claires

    Voici donc un lien qui t'expliquera le principe :

    http://drq.developpez.com/dotnet/articles/threads/#L5
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  15. #35
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Citation Envoyé par Goldar
    C'est vrai que mes explications ne sont pas toujours très claires

    Voici donc un lien qui t'expliquera le principe :

    http://drq.developpez.com/dotnet/articles/threads/#L5
    Merci !

  16. #36
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Salut

    j'ai essaye a nouveau ..cela marche en mettant :

    label.refresh()
    apres
    label.text = ....

    sinon y a t il posibilite d'eviter le "bug" quand j'essaie de deplacer la fenetre ... il met la fenetre en blanc et "ne reponds pas" ....

    @+

  17. #37
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    Tu es sûr que tu ne fais pas une boucle dans l'évènement Tick de ton Timer ?
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  18. #38
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    J'ai pas de timer ...

    voici le code de la form :

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using AppThread;
     
    namespace TestThread
    {
        public partial class FRM_Prog : Form
        {
            theThread_Scan aScan;
     
            public FRM_Prog()
            {
                InitializeComponent();
                aScan = new theThread_Scan();
            }
     
            private void FRM_Prog_Shown(object sender, EventArgs e)
            {               
                aScan.Start();
     
                while (aScan.isAlive())
                {
                    label1.Text = aScan.Prog.ToString();
                    label1.Refresh();
                    progressBar1.Value = aScan.Prog;
                }
            }
        }
    }
    et celui du thread :

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.Data;
    using System.Collections;
    using System.ComponentModel;
     
     
    namespace AppThread
    {
        class theThread_Scan
        {
            private int iProg;
            private Thread ThreadScan;
     
            public int Prog
            {
                get { return iProg; }
            }
     
            public theThread_Scan()
            {
                iProg = 0;
                this.ThreadScan = new Thread(new ThreadStart(ThreadLoop));
                this.ThreadScan.Name = "TEST_THREAD";            
            }
     
            public void Start()
            {
                this.ThreadScan.Start();
            }
     
            public bool isAlive()
            {
                return this.ThreadScan.IsAlive;
            }
     
            public void Stop()
            {
                this.ThreadScan.Abort();
            }
     
            private void ThreadLoop()
            {
                for (int i = 0; i < 100; i++)
                {
                    iProg++;
                    Thread.Sleep(100);                
                }
            }
        }
    }

  19. #39
    Rédacteur

    Avatar de Jérôme Lambert
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2003
    Messages
    4 451
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 451
    Points : 14 357
    Points
    14 357
    Par défaut
    J'avais pourtant expliqué qu'il fallait faire ça avec un timer.

    Tu en reviens au problème que ta classe Form lors de l'évènement shown boucle... Du coup, elle se fige et ne réagira à tes cliques où n'importe quoi d'autre uniquement quand la boucle de l'évènement shown sera finie.

    Le but est donc de rajouter un timer qui a chaque seconde va exécuter le code suivant (comme tu le vois, l'évènement Tick ne boucle pas... D'où la fenêtre n'est pas figée) :

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using AppThread;
     
    namespace TestThread
    {
        public partial class FRM_Prog : Form
        {
            theThread_Scan aScan;
            Timer myTimer;
     
     
            public FRM_Prog()
            {
                InitializeComponent();
                aScan = new theThread_Scan();
            }
     
            void myTimer_Tick(object sender, EventArgs e)
            {
                if (aScan.isAlive())
                {
                    label1.Text = aScan.Prog.ToString();
                    label1.Refresh();
                    progressBar1.Value = aScan.Prog;
                }
                else
                {
                    // Le thread est fini, on peut arrêter le timer
                    myTimer.Stop();
                }
            }
     
            private void FRM_Prog_Shown(object sender, EventArgs e)
            {
                aScan.Start();
     
                // Création du Timer
                myTimer = new Timer();
     
                // Création du handler de l'évènement Tick
                myTimer.Tick += new EventHandler(myTimer_Tick);
     
                // Le timer s'exécutera toutes les secondes
                myTimer.Interval = 1000;
     
                // Démarrage du timer
                myTimer.Start();
            }
        }
    }
    Jérôme Lambert
    Développeur, Architecte, Rédacteur & Fan technologies Microsoft
    Ma boite informatique | Mon profil LinkedIn

  20. #40
    Membre averti Avatar de Seth77
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2005
    Messages
    1 448
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Octobre 2005
    Messages : 1 448
    Points : 410
    Points
    410
    Par défaut
    Citation Envoyé par Goldar
    J'avais pourtant expliqué qu'il fallait faire ça avec un timer.

    Tu en reviens au problème que ta classe Form lors de l'évènement shown boucle... Du coup, elle se fige et ne réagira à tes cliques où n'importe quoi d'autre uniquement quand la boucle de l'évènement shown sera finie.

    Le but est donc de rajouter un timer qui a chaque seconde va exécuter le code suivant (comme tu le vois, l'évènement Tick ne boucle pas... D'où la fenêtre n'est pas figée) :

    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
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using AppThread;
     
    namespace TestThread
    {
        public partial class FRM_Prog : Form
        {
            theThread_Scan aScan;
            Timer myTimer;
     
     
            public FRM_Prog()
            {
                InitializeComponent();
                aScan = new theThread_Scan();
            }
     
            void myTimer_Tick(object sender, EventArgs e)
            {
                if (aScan.isAlive())
                {
                    label1.Text = aScan.Prog.ToString();
                    label1.Refresh();
                    progressBar1.Value = aScan.Prog;
                }
                else
                {
                    // Le thread est fini, on peut arrêter le timer
                    myTimer.Stop();
                }
            }
     
            private void FRM_Prog_Shown(object sender, EventArgs e)
            {
                aScan.Start();
     
                // Création du Timer
                myTimer = new Timer();
     
                // Création du handler de l'évènement Tick
                myTimer.Tick += new EventHandler(myTimer_Tick);
     
                // Le timer s'exécutera toutes les secondes
                myTimer.Interval = 1000;
     
                // Démarrage du timer
                myTimer.Start();
            }
        }
    }

    Ahhhh ok ... donc le prob que j'avais c'etait que la maj se faisait tout le temps (comme j'avais ma boucle il n'en sortait jamais!)...on resout le prob en ne faisant un refresh que toutes les secondes ...

    Il y a juste un bout de code que je ne comprend pas (surtout le +=) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    // Création du handler de l'évènement Tick
    myTimer.Tick += new EventHandler(myTimer_Tick);
    thx @+

Discussions similaires

  1. Réponses: 1
    Dernier message: 20/04/2010, 13h58
  2. executer un main() dans une fenetre
    Par elric63 dans le forum Windows
    Réponses: 1
    Dernier message: 09/06/2009, 14h58
  3. Réponses: 2
    Dernier message: 02/01/2008, 15h31
  4. [Debutant] Un thread qui dessine sur une fenetre ???
    Par Spartan03 dans le forum OpenGL
    Réponses: 6
    Dernier message: 05/04/2006, 20h19
  5. [Thread] laisser une fenetre s'afficher
    Par parisjohn dans le forum Concurrence et multi-thread
    Réponses: 11
    Dernier message: 25/08/2004, 15h05

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