utilisation du backgroundworker
Bonjour à tous amis(e) développeurs :D
Après de nombre recherche sur Google et pas mal de lecture http://glarde.developpez.com/dotnet/bgworker/vb/,
je n'arrive toujours pas à me dépatouiller avec ce composant.
Concrètement, j'ai un bouton ou se déroule bon nombre de calcul du type :
Code:
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
|
Form2.show
Label1.text = "Etat : Etape 1/..."
If CheckBox1.Checked = True And ComboBox2.Text = "45x40" Then
Label94.Text = TextBox30.Text
Label178.Text = "Prix en euros"
End If
If CheckBox1.Checked = True And ComboBox2.Text = "60x40" Then
Label94.Text = TextBox29.Text
Label178.Text = "Prix en euros"
End If
If CheckBox1.Checked = True And ComboBox2.Text = "65x40" Then
Label94.Text = TextBox28.Text
Label178.Text = "Prix en euros"
End If
etc.....
Label1.text = "Etat : Etape 1/..."
If CheckBox1.Checked = True And ComboBox2.Text = "75x40" Then
Label94.Text = TextBox27.Text
Label178.Text = "Prix en euros"
End If
If CheckBox1.Checked = True And ComboBox2.Text = "75x50" Then
Label94.Text = TextBox26.Text
Label178.Text = "Prix en euros"
End If
If CheckBox1.Checked = True And ComboBox2.Text = "75x60" Then
Label94.Text = TextBox25.Text
Label178.Text = "Prix en euros"
End If
etc.... |
ou les label me donnent de résultat de prix....Bref
Je souhaites "suivre" le déroulement de toutes ces actions par un label1 qui afficherai mon état pendant le calcul et pourquoi pas une progressbar1.
J'ai donc créé un petite form2 ou j'y ai mi mon label et ma progressbar qui ce lance avant tous les calculs... mais l'application ce fige... et rien n'est visible.
Est-ce qu'un backgroundworker serait adapté pour ce que je souhaites faire et comment faire ??
J'ai as peu prés saisie ce genre de chose :
Code:
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
| Private WithEvents BackgroundWorker1 As System.ComponentModel.BackgroundWorker
BackgroundWorker1 = New System.ComponentModel.BackgroundWorker
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.WorkerSupportsCancellation = True
AddHandler BackgroundWorker1.DoWork, AddressOf BackgroundWorker1_DoWork
AddHandler BackgroundWorker1.RunWorkerCompleted, AddressOf BackgroundWorker1_RunWorkerCompleted
AddHandler BackgroundWorker1.ProgressChanged, AddressOf BackgroundWorker1_ProgressChanged
Private Sub buttonstart_Click( _ByVal sender As System.Object, _ByVal e As System.EventArgs) _Handles btnStartCancel.Click
RunWorkerAsync ??
Private Sub "inconnu ?"_DoWork( _ByVal sender As System.Object, _ByVal e As System.ComponentModel.DoWorkEventArgs) _Handles "inconnu ?".DoWork
-> Réalisation des traitement :
If CheckBox1.Checked = True And ComboBox2.Text = "45x40" Then
Label94.Text = TextBox30.Text
Label178.Text = "Prix en euros"
End If
Suite des calcul etc....
Private Sub "inconnu ?"_RunWorkerCompleted( _ByVal sender As Object, _ByVal e As RunWorkerCompletedEventArgs) _Handles "inconnue ?".RunWorkerCompleted
If Not (e.Error Is Nothing) Then
label1.Text = "Une erreur est survenue ! Détail : " + e.Error.Message
ElseIf e.Cancelled Then
label1.Text = "Opération annulée !"
Else
label1.Text = "Opération terminée ! Résultat : " + e.Result.ToString
End If
End Sub |
"inconnu" étant ce que je ne sais pas faire comme je débute...
Pourriez-vous m'aider à avancer si vous aviez des idée un peu plus concrête sur la chose ou bien même des exemples qui puissent m'aiguiller ?? :roll:
Merci beaucoup,