Ist das so in Ordnung ?
Aufruf & Update :
Verschoben aus "Sonstige Problemstellungen". ~Thunderbolt
VB.NET-Quellcode
- Option Strict On
- Imports System.IO
- Imports System.Net
- Public Class DataDownload
- Private WithEvents wClient As New WebClient
- Public Event UpdateDataDownloadProgressBar As EventHandler(Of UpdateDataDownloadProgressBar)
- Public Sub DataBrowserServerAdresse(ByVal BaseUrl As String, ByVal FilePath As String, ByVal FileName As String)
- Dim FolderBrowserDialog1 As New FolderBrowserDialog
- If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
- If wClient.IsBusy = False Then
- wClient = New WebClient()
- wClient.Proxy = Nothing
- Try
- wClient.DownloadFileAsync(New Uri(BaseUrl & "DataDownload.php?FilePath=" & FilePath), Path.Combine(FolderBrowserDialog1.SelectedPath, FileName))
- Catch ex As Exception
- If System.IO.File.Exists(Path.Combine(FolderBrowserDialog1.SelectedPath, FileName)) = True Then
- System.IO.File.Delete(Path.Combine(FolderBrowserDialog1.SelectedPath, FileName))
- End If
- _UpdateDataDownloadProgressBar(0)
- MessageBox.Show(ex.Message.ToString, "Fehler !", MessageBoxButtons.OK, MessageBoxIcon.Error)
- End Try
- Else
- wClient.CancelAsync()
- If System.IO.File.Exists(Path.Combine(FolderBrowserDialog1.SelectedPath, FileName)) = True Then
- System.IO.File.Delete(Path.Combine(FolderBrowserDialog1.SelectedPath, FileName))
- End If
- End If
- End If
- End Sub
- Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles wClient.DownloadProgressChanged
- _UpdateDataDownloadProgressBar(e.ProgressPercentage)
- End Sub
- Private Sub DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles wClient.DownloadFileCompleted
- Dim timeOut As Date = Date.Now().AddMilliseconds(500)
- While timeOut > Date.Now
- Application.DoEvents()
- End While
- _UpdateDataDownloadProgressBar(0)
- Console.Beep(CInt("2000"), CInt("500"))
- End Sub
- Private Sub _UpdateDataDownloadProgressBar(ByVal DownloadFortschritt As Integer)
- RaiseEvent UpdateDataDownloadProgressBar(Me, New UpdateDataDownloadProgressBar(DownloadFortschritt))
- End Sub
- End Class
- Public Class UpdateDataDownloadProgressBar : Inherits EventArgs
- Public ReadOnly DownloadProgressBar As Integer
- Public Sub New(ByVal DownloadFortschritt As Integer)
- DownloadProgressBar = DownloadFortschritt
- End Sub
- End Class
Aufruf & Update :
VB.NET-Quellcode
- Private WithEvents DD As New DataDownload
- Private Sub Dateidownload_Click(sender As Object, e As EventArgs) Handles Dateidownload.Click
- DD.DataDownloadAdresse(BaseUrl, FilePath ,FileName)
- End Sub
- Private Sub UpdateDataDownloadProgressBar(ByVal sender As Object, ByVal e As UpdateDataDownloadProgressBar) Handles DD.UpdateDataDownloadProgressBar
- label1.Text = e.DownloadProgressBar & " %"
- End Sub
Verschoben aus "Sonstige Problemstellungen". ~Thunderbolt
Dieser Beitrag wurde bereits 6 mal editiert, zuletzt von „Marcus Gräfe“ ()