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

VB.NET Discussion :

Problème de Timer


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 76
    Points : 32
    Points
    32
    Par défaut Problème de Timer
    Bonjour,
    J'ai un problème de Timer qui ralenti après un certain temps (quelques minutes) à cause d'un graphe sur le même Form et qui utilise deux autres Timer.
    Le premier Timer incrémente un compteur dans un richtextBox en milliseconde, et il marche normalement quand j’arrête le timer du Graphe,sinon il est perturbé par ce dernier et ralenti le compteur ce qui engendre des fausses valeurs (des durées des trames).
    Donc je veux essayer c'est de mettre le timer_tick du timer du graphe sur un autre Thread mais je ne sais pas comment le faire,ou sinon utiliser un autre type de Timer peut être (autre que Formtimer)

    Merci

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    il doit y avoir le threading.timer
    par contre je crois qu'il lève son event (ca doit pas etre tick le nom d'ailleurs) sur un autre thread donc il faut penser à invoker
    et si le traitement prend plus de temps que le timer peut etre que l'event s'empile contraitement au forms.timer
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 76
    Points : 32
    Points
    32
    Par défaut
    Merci,
    Je voulais d'abord essayer de mettre le timer_tick sur un autre thread, quelqu'un pourra m'indiquer comment le faire? j'ai essayé cela mais ça ne marche pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    Private th As System.Threading.Thread
    ..........
     
    th = New System.Threading.Thread(Timer2_Tick) 
    th.Start()
    Merci

  4. #4
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    pas possible

    depuis le tick par contre tu peux appeler un thread sur une sub, en ayant déplacé le code du tick vers cette sub
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  5. #5
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 76
    Points : 32
    Points
    32
    Par défaut
    Si je mets le code de timer_tick dans une sub,comment va-t il s"exécuter automatiquement?

  6. #6
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    dim th as new thread(addressof lasub)
    th.start
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  7. #7
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 76
    Points : 32
    Points
    32
    Par défaut
    J'ai testé mais ça donne erreur d'inter threads
    Images attachées Images attachées  

  8. #8
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    je pensais qu'on en avait déjà parlé, sinon je t'aurais prévenu ...

    depuis un thread il est interdit de modifier les controles

    quand c'est du ponctuel (une ou deux modif depuis le thread) on passe par des invoke pour chaque modif
    si c'est pour plein de chose (comme une liste) il convient de remplir une variable avec les données, puis à la fin de la lecture d'invoker pour afficher les données de la variable dans les controles

    google aura des exemples d'invoke (opération inter thread dans google donne déjà des réponses)
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  9. #9
    Nouveau membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2013
    Messages : 76
    Points : 32
    Points
    32
    Par défaut
    j'ai pas réussi à faire des Invoke sur ma procédure,voici le code de timer_tick que je veux mettre sur un autre 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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
     
     Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer2.Tick
     
             If Chart1HorizontalScroll = 0 Then
                If Chart1.ChartAreas(0).AxisX.Maximum > Chart1.ChartAreas(0).AxisX.ScaleView.Size Then
                    Chart1.ChartAreas(0).AxisX.ScaleView.Scroll(Chart1.ChartAreas(0).AxisX.Maximum)
                End If
            End If
     
            If G1 = 20 Then
     
            ElseIf G1 = 21 Then
                RichTextBox1.AppendText("MRM 1 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
                A1 = 28
            ElseIf G1 = 22 Then
     
                RichTextBox1.AppendText("MRM 1 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
                A1 = 27
            End If
            If H1 = 20 Then
     
            ElseIf H1 = 21 Then
                RichTextBox1.AppendText("MRM 2 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            ElseIf H1 = 22 Then
                RichTextBox1.AppendText("MRM 2 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            End If
            If I1 = 20 Then
     
            ElseIf I1 = 21 Then
                RichTextBox1.AppendText("MRM 3 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            ElseIf I1 = 22 Then
                RichTextBox1.AppendText("MRM 3 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            End If
            If J1 = 20 Then
     
            ElseIf J1 = 21 Then
                RichTextBox1.AppendText("MRM 4 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            ElseIf J1 = 22 Then
                RichTextBox1.AppendText("MRM 4 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            End If
            If K1 = 20 Then
     
            ElseIf K1 = 21 Then
                RichTextBox1.AppendText("MRM 5 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            ElseIf K1 = 22 Then
                RichTextBox1.AppendText("MRM 5 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            End If
            If L1 = 20 Then
     
            ElseIf L1 = 21 Then
                RichTextBox1.AppendText("MRM 6 => NOK : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
            ElseIf L1 = 22 Then
                RichTextBox1.AppendText("MRM 6 => Deconnected : " & DateTime.Now.ToString & vbCrLf)
                RichTextBox1.ScrollToCaret()
     
            End If
     
            Dim DTNow1 As String = DateTime.Now.ToString
            Dim DTNow1Split() As String = DTNow1.Split(" "c)
            Chart1.Series("MRM1").Points.AddY(A1)
            For Each Point As DataPoint In Chart1.Series("MRM1").Points
                If Point.YValues(0) = 29 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 28 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 27 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 26 Then
                    Point.Color = Color.White
                End If
            Next
            Chart1.Series("MRM2").Points.AddY(B1)
            For Each Point As DataPoint In Chart1.Series("MRM2").Points
                If Point.YValues(0) = 24 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 23 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 22 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 21 Then
                    Point.Color = Color.White
                End If
     
            Next
            Chart1.Series("MRM3").Points.AddY(C1)
            For Each Point As DataPoint In Chart1.Series("MRM3").Points
                If Point.YValues(0) = 19 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 18 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 17 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 16 Then
                    Point.Color = Color.White
                End If
            Next
            Chart1.Series("MRM4").Points.AddY(D1)
            For Each Point As DataPoint In Chart1.Series("MRM4").Points
                If Point.YValues(0) = 14 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 13 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 12 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 11 Then
                    Point.Color = Color.White
                End If
            Next
            Chart1.Series("MRM5").Points.AddY(E1)
            For Each Point As DataPoint In Chart1.Series("MRM5").Points
                If Point.YValues(0) = 9 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 8 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 7 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 6 Then
                    Point.Color = Color.White
                End If
            Next
            Chart1.Series("MRM6").Points.AddY(F1)
            For Each Point As DataPoint In Chart1.Series("MRM6").Points
                If Point.YValues(0) = 4 Then
                    Point.Color = Color.LimeGreen
                ElseIf Point.YValues(0) = 3 Then
                    Point.Color = Color.Orange
                ElseIf Point.YValues(0) = 2 Then
                    Point.Color = Color.Red
                ElseIf Point.YValues(0) = 1 Then
                    Point.Color = Color.White
                End If
            Next
            Chart1.Series("MRM1").Points(DTNow1Count).AxisLabel = DTNow1Split(0) & vbCrLf & DTNow1Split(1) & " " 
            DTNow1Count = DTNow1Count + 1
     
            G1 = 0
            H1 = 0
            I1 = 0
            J1 = 0
            K1 = 0
            L1 = 0
     
     
        End Sub
    je ne sais pas comment mettre des Invoke sur les composants du graphe
    merci

Discussions similaires

  1. Toujours un problème avec Timer
    Par adidas40 dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 10/10/2006, 11h04
  2. Problème de Timer
    Par nikus_knx dans le forum MFC
    Réponses: 7
    Dernier message: 18/05/2006, 14h27
  3. Problème de Timer
    Par hammag dans le forum AWT/Swing
    Réponses: 3
    Dernier message: 25/04/2006, 17h52
  4. [VC++ - MFC] Problème de Timer
    Par Alice9 dans le forum MFC
    Réponses: 4
    Dernier message: 08/02/2006, 13h51
  5. [VB6] Problème contrôle Timer et boucle For-Next ...
    Par Stéphane BEHMENBURG dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 01/12/2005, 17h36

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