Ok die Sache hat sich erledigt - Habe eine andere Lösung ohne Threading gefunden.
Hier der Code, für alle die sich einen kleinen Updater ins Program bauen möchten:
Imports System.Windows.Forms
Imports System.Net
Imports System.Security.Policy
Imports System.Threading
Public Class Form1
Private WithEvents httpClient As WebClient
Private URL As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'Auf Updates prüfen
Dim path As String
path = My.Application.Info.DirectoryPath & "\updates\update-true.ini"
'Updateinfos laden
Try
httpClient = New WebClient
Url = "<Webhost, des Updates mit Pfadangabe>"
'z.B. http://www.ich-bin-ein-beispiel.com/updates/update-true.ini
Application.DoEvents()
httpClient.DownloadFileAsync(New Uri(Url), path)
Application.DoEvents()
Catch ex As Exception
MsgBox("Fehler !" & vbNewLine & ex.ToString)
Exit Sub
End Try
End Sub
Private Sub httpClient_DownloadFileCompleted(ByVal sender As Object, ByVal _
e As System.ComponentModel.AsyncCompletedEventArgs) Handles _
httpClient.DownloadFileCompleted
Dim path As String
path = My.Application.Info.DirectoryPath & "\updates\update-true.ini"
MsgBox("Updates wurden vollständig heruntergeladen.", _
MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "Updater")
If MsgBox("Update ausführen ?", MsgBoxStyle.YesNo, "Ausführen") = _
MsgBoxResult.Yes Then
If path = Nothing Then
MsgBox("Update(s) konnte(n) nicht gefunden werden !" & _
vbNewLine & "Updater wird beendet ...", MsgBoxStyle.Critical _
= MsgBoxStyle.OkOnly, "[ERROR]")
GoTo closeme
End If
'Bei Programmen, die heruntergeladene .exe ausführen mit
'Shell(path)
Execution()
On Error GoTo closeme
Else
MsgBox("Speicherpfad :" & vbNewLine & path, _
MsgBoxStyle.Information, "Pfad")
End If
closeme:
End Sub
Private Sub httpClient_DownloadProgressChanged(ByVal sender As Object, _
ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles _
httpClient.DownloadProgressChanged
Me.prgShowUpdateState.Value = e.ProgressPercentage
'Me.prgShowUpdateState
Dim totalBytes As Double = e.TotalBytesToReceive / 1024
Dim Bytes As Double = e.BytesReceived / 1024
Me.lbUpdate.Text = "Downloade " & Bytes & " KB von " & totalBytes & "" & _
"KB"
End Sub
Public Sub Execution()
'IniFileManager ist eine Ini-Hilfsklasse aus dem Internet - einfach mal
' googlen :)
Dim Config As New IniFileManager.IniFileManager
Config.Pfad = My.Application.Info.DirectoryPath & _
"\updates\update-true.ini"
'Überpruefen ob Updates gemacht werden müssen
Dim UpdatesAvailible As String
Dim DoUpdate As Boolean = False
DoUpdate = CBool(Config.ReadValue("Update", "update"))
If DoUpdate = True Then
lbUpdate.Text = "Updates availible."
UpdatesAvailible = Config.ReadValue("Update", "num")
MsgBox("Es sind " & UpdatesAvailible & "Updates verfügbar", _
MsgBoxStyle.Information = MsgBoxStyle.OkOnly, "[Updater]")
Else
MsgBox("Es sind keine Updates vorhanden.", MsgBoxStyle.Information _
= MsgBoxStyle.OkOnly, "[Updater]")
'GoTo noupdate
Exit Sub
End If
End Sub
End ClassTrotzdem vielen Dank.
Mfg IThink
Beitrag wurde zuletzt am 21.06.12 um 09:19:26 editiert. |