Problème inter-thread ? :/
Bonjour,
Je travail actuellement sur une application et celle-ci doit effectuer une vérification de MAJ en arrière plan. Si une mise à jour est détectée, alors, le processus commence le téléchargement et lance l'installation. Jusque là, je n'avait pas de problème. Or j'ai voulus intégrer un système de progressBar et j'avoue être dans le flou total quant aux erreurs se présentant à moi...
Voici déjà mon appel de la fonction principal :
Code:
1 2 3 4 5 6 7 8
| Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Activation de la recherche de MAJ en AP
BackgroundWorker1.WorkerReportsProgress = True
BackgroundWorker1.WorkerSupportsCancellation = True
BackgroundWorker1.RunWorkerAsync()
End Sub |
Voilà ensuite le morceau de code incluant mon BackgroundWorker1 avec recherche de MAJ via un fichier TXT :
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 42 43 44 45 46 47 48 49 50 51 52
| Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackgroundWorker1.DoWork
'Vérification MAJ
Dim response As HttpWebResponse = Nothing
Dim sr As StreamReader = Nothing
Try
Dim request As HttpWebRequest = CType(WebRequest.Create("https://dl.dropboxusercontent.com/s/6j9hdh7st604ixv/version.txt"), HttpWebRequest)
response = CType(request.GetResponse, HttpWebResponse)
sr = New StreamReader(response.GetResponseStream)
If sr.ReadToEnd <> "0.2.1.0" Then
sr.Close()
MsgBox(MsgMaj, MsgBoxStyle.Information)
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\setup.exe"
If Dir(path) <> "" Then
Kill(path)
End If
Me.ProgressBar1.Visible = True
Me.ProgressBar1.Value = 0
Me.ProgressBar1.Maximum = 100
MAJ = True
httpclient = New WebClient
httpclient.DownloadFileAsync(New Uri("http://xxxxxxxxxxxxxxxxxxxx.fr/setup.exe"), path)
Process.Start(path)
Application.Exit()
Else
'MsgBox("Logiciel à jour", MsgBoxStyle.Information)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
Finally
If Not sr Is Nothing Then sr.Close()
If Not (response Is Nothing) Then
response.Close()
End If
If Not (sr Is Nothing) Then
sr.Close()
End If
End Try
End Sub
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
If Me.InvokeRequired Then
Dim evHandler As DownloadProgressChangedEventHandler = AddressOf BackgroundWorker1_ProgressChanged
Me.Invoke(evHandler, sender, e)
Else
System.Threading.Thread.Sleep(50)
ProgressBar1.Value = e.ProgressPercentage
Label1.Text = TryCast(e.UserState, String)
End If
End Sub |
J'attends de vous quelques réponses, astuces, informations voir même morceau de codes. Tout me sera utile pour comprendre et intégrer au plus vite un code valide.
D'avance, merci.
Cordialement,
BioSs