Hallo Zusammen,
Ich habe aktuell das Problem, dass ich von DownloadfileAsync auf Downloadfile umsteigen muss, da die Async Method für mehrere Downloads in einer Schleife eine Exception hervorruft, die besagt, dass dieser nur 1 mal gleichzeitig verwendet werden kann.
Die Downloadfile Methode erfüllt zwar den zweck, jedoch freezt sie das Programm wieder ein. Mit Google habe ich nicht nur gefunden, wie man eine Datei runterlädt allerdings nicht wie ich diesen Fehler umgehen kann.
Der freeze hört auch genau auf, sobald der Download abgeschlossen ist.
Hier einmal das Skript:
Kann mir Jemand weiterhelfen?
LG
Ich habe aktuell das Problem, dass ich von DownloadfileAsync auf Downloadfile umsteigen muss, da die Async Method für mehrere Downloads in einer Schleife eine Exception hervorruft, die besagt, dass dieser nur 1 mal gleichzeitig verwendet werden kann.
Die Downloadfile Methode erfüllt zwar den zweck, jedoch freezt sie das Programm wieder ein. Mit Google habe ich nicht nur gefunden, wie man eine Datei runterlädt allerdings nicht wie ich diesen Fehler umgehen kann.
Der freeze hört auch genau auf, sobald der Download abgeschlossen ist.
Hier einmal das Skript:
VB.NET-Quellcode
- Private Sub DownloadFile(file As String, pfad As String)
- AddHandler Web.DownloadFileCompleted, AddressOf Downloadfile_complete
- AddHandler Web.DownloadProgressChanged, AddressOf Downloadfile_progress
- Web.Headers("User-Agent") = "Mozilla/4.0"
- Web.Proxy = Nothing
- Web.DownloadFile(New Uri(file), pfad)
- End Sub
- Private Sub Downloadfile_progress(sender As Object, e As DownloadProgressChangedEventArgs)
- Me.ToolStripProgressBar1.Value = e.ProgressPercentage
- lblPercentage.Text = e.ProgressPercentage & "%"
- Dim totalbytes As Double = Math.Round(e.TotalBytesToReceive / 1024 / 1024, 1)
- Dim bytes As Double = Math.Round(e.BytesReceived / 1024 / 1024, 1)
- lblKB.Text = bytes & "\" & totalbytes & "MB"
- End Sub
- Private Sub Downloadfile_complete(sender As Object, e As ComponentModel.AsyncCompletedEventArgs)
- Web.Dispose()
- If My.Settings.OriginalFile = My.Settings.SuggestedFile Then
- DownloadAlbumArt()
- Else
- ConvertFile()
- End If
- 'Dim sourcecode As String = WebBrowser.DocumentText.ToString
- 'Dim artist As String, app As String, title As String
- ''Titel und App bestimmen
- 'Try
- ' Dim Rgx As New System.Text.RegularExpressions.Regex("<META content=\047\042(?<title>.*)\042 on (?<App>.*) from Smule\047 property=\042og\072title\042>")
- ' Dim Match = Rgx.Match(sourcecode)
- ' title = Match.Groups("title").Value
- ' app = Match.Groups("App").Value
- 'Catch ex As Exception
- ' title = "Unknown"
- ' app = "Unknown"
- 'End Try
- ''Artist bestimmen
- 'Try
- ' 'Example Line <meta name="twitter:title" content='""Apologize" on Magic Piano" performed by MarvinKleinMusic">
- ' Dim webtitle As String = sourcecode.Split({"""handle"":"""}, StringSplitOptions.None)(1).Split({""}, StringSplitOptions.None)(CInt(("0")))
- ' Dim TestArray() As String = Split(webtitle, """")
- ' artist = TestArray(0)
- 'Catch ex As Exception
- ' artist = "Unknown"
- 'End Try
- 'Dim MP3FilePath As New TagLib.File.LocalFileAbstraction(My.Settings.OriginalFile)
- 'Dim MP3File As TagLib.File = TagLib.File.Create(MP3FilePath)
- ''ID3 Tags schreiben
- 'MP3File.Tag.Album = app
- 'MP3File.Tag.Title = title
- 'MP3File.Tag.Performers = New String() {artist}
- 'MP3File.Save()
- 'MP3File.Dispose()
- End Sub
Kann mir Jemand weiterhelfen?
LG