[VB.net} Progressbar qui ne progresse pas (bloquée)

arfouille1 Messages postés 3 Date d'inscription lundi 24 janvier 2011 Statut Membre Dernière intervention 20 avril 2011 - 20 avril 2011 à 11:51
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 - 20 avril 2011 à 18:40
Bonjour à tous,

Je suis débutant en programmation et j'aimerais faire un genre d'IHM pour programmer un petit module perso.

Dans cette IHM je veux mettre une progressbar durant le temps de programmation.( je lance un logiciel process en parallele)Il y a 3 etapes, et par consequent 3 boutons

Mon probleme est que ma progressbar ne s'initialise pas correctement. Elle apparait correctement mais elle est dès le début complétée au 1/4 et ne bouge pas.
Par contre si je lance la progressbar à partir d'un autre bouton, tout s'execute correctement.
Voici la partie de mon code pour lancer la progressbar:

 'fenetre d'attente
        Form1.Label3.Text = "Veuillez patienter durant la programmation"
        Form1.PictureBox5.Visible = False
        Form1.Label4.Visible = False
        Form1.Size = New System.Drawing.Size(600, 130)
        Form1.Label3.Size = New System.Drawing.Size(560, 90)

        Form1.PictureBox5.Visible = False
        Form1.PGB.Visible = True
        Form1.PGB.Enabled = True
        Form1.Timer3.Start()
        Form1.PGB.Refresh()
        Form1.Show()
        Form1.Refresh()


        'Lancement du processus de programmation de la carte 
        Dim armon1 As New Process
        armon1.StartInfo = Armon
        armon1.Start()
        Dim armon_out As StreamReader = armon1.StandardOutput
        RichTextBox2.Text = armon_out.ReadToEnd

        If RichTextBox2.Text.Contains("cannot") Then
            Form1.Hide()
            TimerB.Stop()
            MsgBox("Erreur, pas de communication.", , "Erreur")
            Application.Exit()
        End If


et voila mon "form1" appelé :

 <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.PGB = New System.Windows.Forms.ProgressBar()
        Me.bgrLongProcess = New System.ComponentModel.BackgroundWorker()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.PictureBox5 = New System.Windows.Forms.PictureBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Timer3 = New System.Windows.Forms.Timer(Me.components)
        CType(Me.PictureBox5, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'PGB
        '
        Me.PGB.Location = New System.Drawing.Point(-1, 58)
        Me.PGB.Name = "PGB"
        Me.PGB.Size = New System.Drawing.Size(409, 19)
        Me.PGB.Style = System.Windows.Forms.ProgressBarStyle.Continuous
        Me.PGB.TabIndex = 1
        Me.PGB.Visible = False
        '
        'bgrLongProcess
        '
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(59, 9)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(290, 20)
        Me.Label3.TabIndex = 3
        Me.Label3.Text = "Allumez le Colibri en appuyant sur :"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'PictureBox5
        '
        Me.PictureBox5.Image = Global.WindowsApplication1.My.Resources.Resources.boot
        Me.PictureBox5.Location = New System.Drawing.Point(104, 58)
        Me.PictureBox5.Name = "PictureBox5"
        Me.PictureBox5.Size = New System.Drawing.Size(196, 69)
        Me.PictureBox5.TabIndex = 5
        Me.PictureBox5.TabStop = False
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(31, 141)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(364, 60)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "Puis patientez pendant l'initialisation jusqu'à" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & " l'activation de l'étape 3" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "(env" & _
            ". 30 sec.)" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10)
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Timer3
        '
        Me.Timer3.Interval = 10
        '
        'Form1
        '
        Me.AccessibleRole = System.Windows.Forms.AccessibleRole.MenuPopup
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None
        Me.CausesValidation = False
        Me.ClientSize = New System.Drawing.Size(407, 210)
        Me.ControlBox = False
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.PictureBox5)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.PGB)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.ShowIcon = False
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.TopMost = True
        CType(Me.PictureBox5, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    ' Display the progress.
    Private Sub bgrLongProcess_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgrLongProcess.ProgressChanged
        Me.PGB.Value = e.ProgressPercentage
    End Sub


    Private Sub PB()
        'Timer3.Interval = 390
        Timer3.Start()
    End Sub
    Public Sub Timer3_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick


        Static c As Integer
        c += 1


        PGB.Minimum = 0
        PGB.Maximum = 100
        PGB.Visible = True
        PGB.Step = 1

        If c > 100 Then c = 1

        PGB.Value = c

        'Me.Refresh()

        PGB.Refresh()
        Me.PGB.PerformStep()

        Me.Update()


        If PGB.Value = PGB.Maximum Then

            Timer3.Stop()
            'Me.Hide()

        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PGB.Value = 0
        Me.PGB.PerformStep()
        Dim Thread_PB As Thread = New Thread(New ThreadStart(AddressOf PB))
        Thread_PB.Start()
    End Sub
End Class


J'espere avoir été assez précis sur la description.

Merci d'avance

4 réponses

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
20 avril 2011 à 12:13
Salut

Es-tu sûr que ton Timer3 est démarré ?
Es-tu sûr que tu passes dans Timer3_tick
PGB.Value = c et Me.PGB.PerformStep() sont des doublons

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
0
arfouille1 Messages postés 3 Date d'inscription lundi 24 janvier 2011 Statut Membre Dernière intervention 20 avril 2011
20 avril 2011 à 13:51
Merci pour Jack pour ta réponse rapide.
Le timer 3 semble démarrer (comment en etre sur?)
je ne passe pas dans le timer3_tick. Je n'avais pas fait attention à ca.
J'y passe par contre lorsque je lance ma progressbar à partir d'un autre bouton (lorsque je ne lance pas en parallele mon precess de mise à jour)

J'ai supprimé le doublons, merci
0
arfouille1 Messages postés 3 Date d'inscription lundi 24 janvier 2011 Statut Membre Dernière intervention 20 avril 2011
20 avril 2011 à 14:29
Après test, je m'aperçois que je passe dans mon timer3_tick après mon process de programmation et on meme temps.

J'ai testé auparavant avec un backgroundworker, j'avais le phenomene inverse.
0
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
20 avril 2011 à 18:40
Pense aussi au debogage ligne à ligne :
- F9 sur une ligne de code
Le programme s'y arrêtera au prochain passage
Survole avec la souris tes variables pour visualiser leur contenu, ou va dans la fenêtre de debogage (Ctrl-G) et tape
? maVariable
pour qu'elle s'inscrive dans la fenêtre.
- F8 (VB6) ou F10 (.Net) pour avancer d'une ligne de code
- F5 pour continuer normalement
0
Rejoignez-nous