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 :

Backgroundworker et timer


Sujet :

VB.NET

  1. #1
    Membre du Club
    Homme Profil pro
    Inscrit en
    Octobre 2006
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2006
    Messages : 103
    Points : 64
    Points
    64
    Par défaut Backgroundworker et timer
    Bonjour,

    Je vais essayer d'être le plus clair dans mes explications.

    Ce que je cherche :
    - Mettre un traitement de code long qui actuellement dans un timer, dans un background worker cadencée par le timer.
    - J'ai déjà fait plusieurs recherche et essai et j'ai toujours le même défaut.

    Défaut :
    Dans le bgw :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Me.TabPage3.BackColor = Grap_fond
    => Plantage avec message
    ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Me.TabPage3.Controls.Add(Chart2)
    => Plantage avec message
    ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.

    Bien que j'ai fait mes diverses recherche sur un problème de Thread, je ne comprends pas.

    Questions :

    QU'elle est vraiment ce défaut car je le comprends pas vraiment? => Pour moi le pb vient du fait que je souhaite faire un changement d'état d'un objet!
    Comment puis-je corrigé et arriver a faire ce traitement en fond de tache.

    Merci d'avance.

    Cordialement.


    Voici le code total :
    Timer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
      Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            BackgroundWorker1.WorkerReportsProgress = True
            BackgroundWorker1.WorkerSupportsCancellation = True
            If BackgroundWorker1.IsBusy <> True Then
                BackgroundWorker1.RunWorkerAsync()
            End If
     
        End Sub

    bgw :
    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
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     
            'Créer un Chart
            Dim Chart2 As New Chart
     
            ' Créer ChartArea (zone graphique)
            Dim ChartArea1 As New ChartArea()
     
            ' Ajouter le  Chart Area à la Collection ChartAreas du  Chart
            Chart2.ChartAreas.Add(ChartArea1)
     
            type_fond_graph()
            type_axe_graph()
            type_axe_sec_graph()
     
            ' Définition du fond
            Chart2.BackColor = Grap_fond
            ChartArea1.BackColor = Grap_fond
            Me.TabPage3.BackColor = Grap_fond
            ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé
     
     
            '--------------------------------------------------------------------------------------
     
            ' Coloration Axe X Principale
            ChartArea1.AxisX.LineColor = Grap_axe
            ChartArea1.AxisX.MajorGrid.LineColor = Grap_axe
            ChartArea1.AxisX.LabelStyle.ForeColor = Grap_axe
            ChartArea1.AxisX.MajorTickMark.LineColor = Grap_axe
     
     
            ' Coloration Axe Y Principale
            ChartArea1.AxisY.LineColor = Grap_axe
            ChartArea1.AxisY.MajorGrid.LineColor = Grap_axe
            ChartArea1.AxisY.LabelStyle.ForeColor = Grap_axe
            ChartArea1.AxisY.MajorTickMark.LineColor = Grap_axe
     
            If Echelle_Manuel.Checked = True Then
                ' Définition de la configuration des axes.
                ' Tracer Axe X Principale
     
                ChartArea1.AxisX.Minimum = Grap_Axe_X_Min
                ChartArea1.AxisX.Maximum = Grap_Axe_X_Max
                ChartArea1.AxisX.Interval = Grap_Axe_X_Interval_Label ' affichage Label de l'axe X tout les N
                ChartArea1.AxisX.MajorGrid.Interval = Grap_Axe_X_Interval_Label       ' Pas du quadrillage ->  1 Division
                ChartArea1.AxisX.MajorTickMark.Interval = Grap_Axe_X_Interval_Label / 2 ' Pas de l'axe -> 1/2 Divison
     
                ' Tracer Axe Y Principale
                ChartArea1.AxisY.Minimum = Grap_Axe_Y_Min
                ChartArea1.AxisY.Maximum = Grap_Axe_Y_Max
                ChartArea1.AxisY.Interval = Grap_Axe_Y_Interval_Label ' Label de l'axe Y
                ChartArea1.AxisY.MajorGrid.Interval = Grap_Axe_Y_Interval_Label  ' Pas du quadrillage
                ChartArea1.AxisY.MajorTickMark.Interval = Grap_Axe_Y_Interval_Label / 2 ' Pas de l'axe
                ChartArea1.AxisY.Interval = Grap_Axe_Y_Interval_Label ' Label de l'axe Y
     
            End If
            '--------------------------------------------------------------------------------------
            If Axe_Secondaire.Checked = True Then
                ' Axe X Secondaire
                ' Affichage de l'axe secondaire 
                ChartArea1.AxisX2.Enabled = AxisEnabled.True
                'Suppression des label de l'axe secondaire
                ChartArea1.AxisX2.LabelStyle.Enabled = False
     
                ' Coloration
                ChartArea1.AxisX2.LineColor = Grap_axe_sec
                ChartArea1.AxisX2.MajorGrid.LineColor = Grap_axe_sec
                ChartArea1.AxisX2.LabelStyle.ForeColor = Grap_axe_sec
                ChartArea1.AxisX2.MajorTickMark.LineColor = Grap_axe_sec
                ' Tracer
                ChartArea1.AxisX2.Minimum = Grap_Axe_X_Min
                ChartArea1.AxisX2.Maximum = Grap_Axe_X_Max
                ChartArea1.AxisX2.Interval = Grap_Axe_X_Interval_Label / 2
     
                ' Axe Y Secondaire
                ' Affichage de l'axe secondaire 
                ChartArea1.AxisY2.Enabled = AxisEnabled.True
                'Suppression des label de l'axe secondaire
                ChartArea1.AxisY2.LabelStyle.Enabled = False
                ' Coloration
                ChartArea1.AxisY2.LineColor = Grap_axe_sec
                ChartArea1.AxisY2.MajorGrid.LineColor = Grap_axe_sec
                ChartArea1.AxisY2.LabelStyle.ForeColor = Grap_axe_sec
                ChartArea1.AxisY2.MajorTickMark.LineColor = Grap_axe_sec
     
                ' Tracer
                ChartArea1.AxisY2.Minimum = Grap_Axe_Y_Min
                ChartArea1.AxisY2.Maximum = Grap_Axe_Y_Max
                ChartArea1.AxisY2.MajorGrid.Interval = Grap_Axe_Y_Interval_Label / 2
            End If
            '--------------------------------------------------------------------------------------
     
            ' Initialisation de la variable
            i = 1
            L = 0
            Chart2.Series.Clear()
            'Création du nombre de serie en fonction de Nombre de voie selectionnées
            Do While (L <= Nbr_control And i <= Nbr_ES)
                Dim lp = Grap_Nom_InOut
                If Grap_Nom_InOut(i) <> Nothing And i <= Nbr_ES Then
                    'Chart2.Series.Add(i).Name = Grap_Sel_CB(i) Then
                    ' Else
                    Chart2.Series.Add(L).Name = Grap_Nom_InOut(i) & " - " & Grap_Unit(i)
                    L = L + 1
                End If
                i = i + 1
            Loop
     
            Dim legend As New Legend
            'On l'ajoute à la collection Legends n du Chart
            Chart2.Legends.Add(legend)
            Chart2.Size = New System.Drawing.Size(50, 50)
            ' legend.BackColor = Color.Transparent
     
            'Suppression du graphique
            Suppression_graph()
            ' Gestion du type de graphique
            type_graph()
     
            ' Initialisation de la variable
            i = 0
            J = 0
            L = 0
     
     
            'Replacement des indexation de la variable color
            Do While (L <= Grap_Color.Length - 1)
     
                Grap_Color_Memorie(L) = Grap_Color(L)
     
                If (Grap_Color(L) <> Nothing) Then
                    Grap_Color_Resize(i) = Grap_Color(L)
                    i = i + 1
                End If
                L = L + 1
            Loop
            ' Grap_Color = Grap_Color_Resize
     
            i = 0
            L = 0
            Do While (i < k)
                If J > Nbr_control Then
                    J = Nbr_control
                End If
     
                If (J < Nbr_control And Nbr_control > 0) Then
                    Dim lk = Chart2.Series
                    ' Définition du type de graphique
                    Chart2.Series(J).ChartType = Grap_Type
                    ' Définition des points par séries
                    Chart2.Series(J).Points.AddXY(i, multi(J, i))
     
                    ' Définition de la zone d'affichage
                    Chart2.Series(J).ChartArea = "ChartArea1"
                    ' Custom du graphique - Epaisseur des courbes
                    Chart2.Series(J).BorderWidth = 1
     
                    ' Custom du graphique - Couleur des courbes
                    Chart2.Series(J).Color = Grap_Color_Resize(J) 'Grap_Color(J)
     
                    'Affichage des marqueurs numérique
                    If Marqueur_Numerique.Checked = True Then
                        Chart2.Series(J).LabelForeColor = Grap_Color_Resize(J)
                        Chart2.Series(J).IsValueShownAsLabel = True
                    End If
     
                    'Affichage des marqueurs
                    If Marqueur_Box.Checked = True Then
                        Chart2.Series(J).MarkerColor = Grap_Color_Resize(J) 'Color.Cyan
                        Chart2.Series(J).MarkerSize = 5
                        Chart2.Series(J).MarkerStyle = MarkerStyle.Circle
                    End If
     
                    '   If (Grap_Color(L) <> Nothing) Then
                    ' If (J <> Nbr_control And Nbr_control > 0) Then
                    J = J + 1
                    'End If
                    ' End If
     
                    '   If Grap_Nbpts_mesure = (Grap_Compteur_Nbpts) And Grap_Type_mesure = "Point" Then
                    'Timer1.Stop()
                Else
                    J = 0
                    ' End If
                    '  Grap_Compteur_Nbpts = Grap_Compteur_Nbpts + 1
     
                End If
                L = L + 1
                i = i + 1
            Loop
     
            ' Initialisation de la variable
            i = 0
            'M = M + 1
            'Définition de la position du graphique
            Chart2.Location = New System.Drawing.Point(0, 0)
     
            ' Dimension du graphique
            Chart2.Size = New System.Drawing.Size(Me.TabPage3.Width - 10, Me.TabPage3.Height - 25)
     
            ' Ajouter le chart à la form
            Me.TabPage3.Controls.Add(Chart2)
            ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
     
     
            ' If TabControl1.SelectedIndex = 2 Then
            ' If Grap_duree_mesure = (Grap_Compteur_Temps / 1000) And Grap_Type_mesure = "Durée" Then
            ' Timer1.Stop()
            ' End If
            ' Grap_Compteur_Temps = Grap_Compteur_Temps + Timer1.Interval
            ' End If
            Chart = Chart2
            '  ControlBmpToFile(Chart, "tet")
     
        End Sub

  2. #2
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2013
    Messages
    235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2013
    Messages : 235
    Points : 359
    Points
    359
    Par défaut
    Bonjour,

    Sur MSDN ils expliquent comment utiliser le multi-thread de façon sure sur cette page:

    https://msdn.microsoft.com/fr-fr/lib...vs.110%29.aspx

    Il est risqué d'appeler un contrôle à partir d'un thread autre que celui qui a créé le contrôle sans utiliser la méthode Invoke.
    Voici un exemple d'appel (en bas de page) qui est thread-safe.
    Par nature les mots, ils sont flous, c'est une fois alignés qu'ils se précisent.

  3. #3
    Membre éclairé Avatar de r.morel
    Homme Profil pro
    Dessinateur CAO
    Inscrit en
    Août 2014
    Messages
    336
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Dessinateur CAO
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2014
    Messages : 336
    Points : 667
    Points
    667
    Par défaut
    Salut,

    => Plantage avec message
    ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé
    Cela vient du fait que dans ton backgroundworker tu fais référence à ton formulaire par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Me.TabPage3.BackColor = Grap_fond
    Or dans un backgroundworker tu ne peux pas faire référence à un élément qui ne fait pas parti du même thread. Donc tu dois externaliser le changement du formulaire. Par exemple en faisant passer un paramètre au thread qu'il peut faire évoluer et ainsi déclencher un code externe qui fera la modification du formulaire.
    Merci de ainsi que d'utiliser les boutons et

  4. #4
    Expert confirmé Avatar de ed73170
    Homme Profil pro
    Développeur indépendant
    Inscrit en
    Mai 2009
    Messages
    765
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur indépendant

    Informations forums :
    Inscription : Mai 2009
    Messages : 765
    Points : 5 522
    Points
    5 522
    Par défaut
    Pour accéder à un contrôle à partir d'un autre thread que celui qui l'a créé il faut utiliser Control.Invoke. Tu trouveras les explications ici : https://msdn.microsoft.com/fr-fr/lib...v=vs.110).aspx

  5. #5
    Membre du Club
    Homme Profil pro
    Inscrit en
    Octobre 2006
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2006
    Messages : 103
    Points : 64
    Points
    64
    Par défaut Suite #1
    Bonjour,

    après avoir regarder les diverses informations fournis, j'ai essayé ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     Private Sub Tabpage_set()
            If Me.TabPage3.InvokeRequired Then
                Me.TabPage3.Invoke(New MethodInvoker(AddressOf Tabpage_set))
            Else
                Me.TabPage3.BackColor = Grap_fond
            End If
        End Sub
    Même genre de code pour le second défaut.

    Ce qui fonctionne semble t il car un début de résultat s'affiche, et au bout de 2 secondes, le défaut apparaît de nouveau sur un autre partir :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ChartArea1.BackColor = Grap_fond
    Donc je pense que je vais avoir le droit de faire ce genre de correction pour chaque défaut!!!

    J'aimerai savoir :
    - Si la méthode utilisé est bonne ?
    - S'il était possible de généraliser la correction ou s'il existe quelque chose de plus simple?

    Merci d'avance.

  6. #6
    Membre éclairé Avatar de r.morel
    Homme Profil pro
    Dessinateur CAO
    Inscrit en
    Août 2014
    Messages
    336
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Dessinateur CAO
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2014
    Messages : 336
    Points : 667
    Points
    667
    Par défaut
    Citation Envoyé par Hybride76 Voir le message
    Bonjour,
    Même genre de code pour le second défaut.

    Ce qui fonctionne semble t il car un début de résultat s'affiche, et au bout de 2 secondes, le défaut apparaît de nouveau sur un autre partir :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ChartArea1.BackColor = Grap_fond
    Donc je pense que je vais avoir le droit de faire ce genre de correction pour chaque défaut!!!
    Salut,
    Pour moi c'est normal puisque le code en question fait parti du backgroundworker et qu'il essaie de modifier le formulaire. Cela n'est pas permit.
    Je pense que tu dois conserver dans le backgroundworker que la partie traitement / calcul. La partie modification de l'interface doit être réalisée en amont.
    A plus.
    Merci de ainsi que d'utiliser les boutons et

  7. #7
    Membre du Club
    Homme Profil pro
    Inscrit en
    Octobre 2006
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2006
    Messages : 103
    Points : 64
    Points
    64
    Par défaut Suite #2
    Bonjour,

    Pour répondre à R.Morel et merci de sa réponse ainsi qu'au autres réponses.


    Je pense que tu dois conserver dans le backgroundworker que la partie traitement / calcul. La partie modification de l'interface doit être réalisée en amont.
    A plus.
    Le soucis c'est que l'ensemble est un calcul puis un traitement du formulaire.

    Dans mon code j'étais parti pour une mise à jour temporel, mais d'un point de vu ressource j'ai pensé qu'il serait mieux dans un backgroundworker, et je n'avais pas imaginé, les problèmes rencontrés.

    Je vais continué à voir ce que je peux faire et dans le pire de cas cela restera sans bgw.

    Encore merci pour vos réponses, en espérant trouvé un solution...

    Cordialement.

    Code :
    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
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
       Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
     
            'Créer un Chart
            Dim Chart2 As New Chart
     
            ' Créer ChartArea (zone graphique)
            Dim ChartArea1 As New ChartArea()
     
            ' Ajouter le  Chart Area à la Collection ChartAreas du  Chart
            Chart2.ChartAreas.Add(ChartArea1)
     
            type_fond_graph()
            type_axe_graph()
            type_axe_sec_graph()
     
            ' Définition du fond
            Chart2.BackColor = Grap_fond
            ChartArea1.BackColor = Grap_fond
            Me.TabPage3.BackColor = Grap_fond
            ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé
     
     
            '--------------------------------------------------------------------------------------
     
            ' Coloration Axe X Principale
            ChartArea1.AxisX.LineColor = Grap_axe
            ChartArea1.AxisX.MajorGrid.LineColor = Grap_axe
            ChartArea1.AxisX.LabelStyle.ForeColor = Grap_axe
            ChartArea1.AxisX.MajorTickMark.LineColor = Grap_axe
     
     
            ' Coloration Axe Y Principale
            ChartArea1.AxisY.LineColor = Grap_axe
            ChartArea1.AxisY.MajorGrid.LineColor = Grap_axe
            ChartArea1.AxisY.LabelStyle.ForeColor = Grap_axe
            ChartArea1.AxisY.MajorTickMark.LineColor = Grap_axe
     
            If Echelle_Manuel.Checked = True Then
                ' Définition de la configuration des axes.
                ' Tracer Axe X Principale
     
                ChartArea1.AxisX.Minimum = Grap_Axe_X_Min
                ChartArea1.AxisX.Maximum = Grap_Axe_X_Max
                ChartArea1.AxisX.Interval = Grap_Axe_X_Interval_Label ' affichage Label de l'axe X tout les N
                ChartArea1.AxisX.MajorGrid.Interval = Grap_Axe_X_Interval_Label       ' Pas du quadrillage ->  1 Division
                ChartArea1.AxisX.MajorTickMark.Interval = Grap_Axe_X_Interval_Label / 2 ' Pas de l'axe -> 1/2 Divison
     
                ' Tracer Axe Y Principale
                ChartArea1.AxisY.Minimum = Grap_Axe_Y_Min
                ChartArea1.AxisY.Maximum = Grap_Axe_Y_Max
                ChartArea1.AxisY.Interval = Grap_Axe_Y_Interval_Label ' Label de l'axe Y
                ChartArea1.AxisY.MajorGrid.Interval = Grap_Axe_Y_Interval_Label  ' Pas du quadrillage
                ChartArea1.AxisY.MajorTickMark.Interval = Grap_Axe_Y_Interval_Label / 2 ' Pas de l'axe
                ChartArea1.AxisY.Interval = Grap_Axe_Y_Interval_Label ' Label de l'axe Y
     
            End If
            '--------------------------------------------------------------------------------------
            If Axe_Secondaire.Checked = True Then
                ' Axe X Secondaire
                ' Affichage de l'axe secondaire 
                ChartArea1.AxisX2.Enabled = AxisEnabled.True
                'Suppression des label de l'axe secondaire
                ChartArea1.AxisX2.LabelStyle.Enabled = False
     
                ' Coloration
                ChartArea1.AxisX2.LineColor = Grap_axe_sec
                ChartArea1.AxisX2.MajorGrid.LineColor = Grap_axe_sec
                ChartArea1.AxisX2.LabelStyle.ForeColor = Grap_axe_sec
                ChartArea1.AxisX2.MajorTickMark.LineColor = Grap_axe_sec
                ' Tracer
                ChartArea1.AxisX2.Minimum = Grap_Axe_X_Min
                ChartArea1.AxisX2.Maximum = Grap_Axe_X_Max
                ChartArea1.AxisX2.Interval = Grap_Axe_X_Interval_Label / 2
     
                ' Axe Y Secondaire
                ' Affichage de l'axe secondaire 
                ChartArea1.AxisY2.Enabled = AxisEnabled.True
                'Suppression des label de l'axe secondaire
                ChartArea1.AxisY2.LabelStyle.Enabled = False
                ' Coloration
                ChartArea1.AxisY2.LineColor = Grap_axe_sec
                ChartArea1.AxisY2.MajorGrid.LineColor = Grap_axe_sec
                ChartArea1.AxisY2.LabelStyle.ForeColor = Grap_axe_sec
                ChartArea1.AxisY2.MajorTickMark.LineColor = Grap_axe_sec
     
                ' Tracer
                ChartArea1.AxisY2.Minimum = Grap_Axe_Y_Min
                ChartArea1.AxisY2.Maximum = Grap_Axe_Y_Max
                ChartArea1.AxisY2.MajorGrid.Interval = Grap_Axe_Y_Interval_Label / 2
            End If
            '--------------------------------------------------------------------------------------
     
            ' Initialisation de la variable
            i = 1
            L = 0
            Chart2.Series.Clear()
            'Création du nombre de serie en fonction de Nombre de voie selectionnées
            Do While (L <= Nbr_control And i <= Nbr_ES)
                Dim lp = Grap_Nom_InOut
                If Grap_Nom_InOut(i) <> Nothing And i <= Nbr_ES Then
                    'Chart2.Series.Add(i).Name = Grap_Sel_CB(i) Then
                    ' Else
                    Chart2.Series.Add(L).Name = Grap_Nom_InOut(i) & " - " & Grap_Unit(i)
                    L = L + 1
                End If
                i = i + 1
            Loop
     
            Dim legend As New Legend
            'On l'ajoute à la collection Legends n du Chart
            Chart2.Legends.Add(legend)
            Chart2.Size = New System.Drawing.Size(50, 50)
            ' legend.BackColor = Color.Transparent
     
            'Suppression du graphique
            Suppression_graph()
            ' Gestion du type de graphique
            type_graph()
     
            ' Initialisation de la variable
            i = 0
            J = 0
            L = 0
     
     
            'Replacement des indexation de la variable color
            Do While (L <= Grap_Color.Length - 1)
     
                Grap_Color_Memorie(L) = Grap_Color(L)
     
                If (Grap_Color(L) <> Nothing) Then
                    Grap_Color_Resize(i) = Grap_Color(L)
                    i = i + 1
                End If
                L = L + 1
            Loop
            ' Grap_Color = Grap_Color_Resize
     
            i = 0
            L = 0
            Do While (i < k)
                If J > Nbr_control Then
                    J = Nbr_control
                End If
     
                If (J < Nbr_control And Nbr_control > 0) Then
                    Dim lk = Chart2.Series
                    ' Définition du type de graphique
                    Chart2.Series(J).ChartType = Grap_Type
                    ' Définition des points par séries
                    Chart2.Series(J).Points.AddXY(i, multi(J, i))
     
                    ' Définition de la zone d'affichage
                    Chart2.Series(J).ChartArea = "ChartArea1"
                    ' Custom du graphique - Epaisseur des courbes
                    Chart2.Series(J).BorderWidth = 1
     
                    ' Custom du graphique - Couleur des courbes
                    Chart2.Series(J).Color = Grap_Color_Resize(J) 'Grap_Color(J)
     
                    'Affichage des marqueurs numérique
                    If Marqueur_Numerique.Checked = True Then
                        Chart2.Series(J).LabelForeColor = Grap_Color_Resize(J)
                        Chart2.Series(J).IsValueShownAsLabel = True
                    End If
     
                    'Affichage des marqueurs
                    If Marqueur_Box.Checked = True Then
                        Chart2.Series(J).MarkerColor = Grap_Color_Resize(J) 'Color.Cyan
                        Chart2.Series(J).MarkerSize = 5
                        Chart2.Series(J).MarkerStyle = MarkerStyle.Circle
                    End If
     
                    '   If (Grap_Color(L) <> Nothing) Then
                    ' If (J <> Nbr_control And Nbr_control > 0) Then
                    J = J + 1
                    'End If
                    ' End If
     
                    '   If Grap_Nbpts_mesure = (Grap_Compteur_Nbpts) And Grap_Type_mesure = "Point" Then
                    'Timer1.Stop()
                Else
                    J = 0
                    ' End If
                    '  Grap_Compteur_Nbpts = Grap_Compteur_Nbpts + 1
     
                End If
                L = L + 1
                i = i + 1
            Loop
     
            ' Initialisation de la variable
            i = 0
            'M = M + 1
            'Définition de la position du graphique
            Chart2.Location = New System.Drawing.Point(0, 0)
     
            ' Dimension du graphique
            Chart2.Size = New System.Drawing.Size(Me.TabPage3.Width - 10, Me.TabPage3.Height - 25)
     
            ' Ajouter le chart à la form
            Me.TabPage3.Controls.Add(Chart2)
            ' Opération inter-threads non valide : le contrôle 'TabPage3' a fait l'objet d'un accès à partir d'un thread autre que celui sur lequel il a été créé.
     
     
            ' If TabControl1.SelectedIndex = 2 Then
            ' If Grap_duree_mesure = (Grap_Compteur_Temps / 1000) And Grap_Type_mesure = "Durée" Then
            ' Timer1.Stop()
            ' End If
            ' Grap_Compteur_Temps = Grap_Compteur_Temps + Timer1.Interval
            ' End If
            Chart = Chart2
            '  ControlBmpToFile(Chart, "tet")
     
        End Sub

  8. #8
    Membre expérimenté
    Homme Profil pro
    Développeur .Net / Delphi
    Inscrit en
    Juillet 2002
    Messages
    738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Développeur .Net / Delphi
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2002
    Messages : 738
    Points : 1 745
    Points
    1 745
    Par défaut
    Bonjour,

    Juste pour info, il est entendu qu'il n'est pas possible de faire des mises à jour d'un Control dans un autre thread que celui qui l'a crée (globalement le thread principal). Il a été dit que Invoke permet cette mise à jour qui sera effectuée donc dans le thread principal. Or si le traitement long passe 90% de son temps à effectuer ces mises à jour du GUI, il passe donc 90% de son traitement dans le thread principal. De ce fait, le thread secondaire n'a que très peu d'intérêt mis à part de rendre le code illisible ;-)
    Reste à savoir quelle est la proportion du temps passé au calcul face au temps passé à la mise à jour de l'interface utilisateur...

  9. #9
    Membre éclairé Avatar de r.morel
    Homme Profil pro
    Dessinateur CAO
    Inscrit en
    Août 2014
    Messages
    336
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Dessinateur CAO
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2014
    Messages : 336
    Points : 667
    Points
    667
    Par défaut
    Citation Envoyé par Hybride76 Voir le message
    Bonjour,
    Le soucis c'est que l'ensemble est un calcul puis un traitement du formulaire.
    Pour moi la logique serait donc
    1. Lancement de la requête au bacground worker
    2. Traitement du calcul par le background worker
    3. Traitement du formulaire une fois le calcul terminé donc pas par le background worker


    A plus
    Merci de ainsi que d'utiliser les boutons et

  10. #10
    Membre chevronné
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2009
    Messages
    1 048
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 048
    Points : 2 201
    Points
    2 201
    Par défaut
    Le background worker a aussi la possibilité d'envoyer au thread principal des notifications à l'aide de la méthode ReportProgress qui lancera un événement sur le thread principal pouvant modifier l'affichage.

    Néanmoins ce canal "inter-thread" a plutôt pour objectif de faire passer une information sur l'avancement d'une procédure plutôt que des résultats intermédiaires.

Discussions similaires

  1. [Débutant] BackgroundWorker et Timer
    Par aimar022 dans le forum VB.NET
    Réponses: 3
    Dernier message: 29/08/2012, 18h28
  2. [Débutant] Timer et BackgroundWorker
    Par Sh4ke dans le forum C#
    Réponses: 2
    Dernier message: 28/06/2012, 18h47
  3. [] [Réseau] Anti-timer, anti-idle
    Par clonevince dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 15/01/2003, 22h19
  4. Timer de précision
    Par guigui dans le forum MFC
    Réponses: 1
    Dernier message: 04/12/2002, 15h21
  5. Timer en µsecondes
    Par Dagobert dans le forum x86 16-bits
    Réponses: 3
    Dernier message: 25/11/2002, 00h59

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