그래서 저는 지금 당분간이 문제를 해결하려고 노력해 왔습니다. 저는 아마추어 프로그래머입니다. 그래서 나는 항상 내가 뭘 잘못하고 있는지 알지 못합니다. 어쨌든WebClient 비동기 다운로더가 제대로 작동하지 않습니다.
, 내 최근 프로젝트의 전제 :
내 친구와 나는 정기적으로 마인 크래프트를 플레이,하지만 그들은 정말 밝은 아니에요, 우리가 개조를 얻고 그들에게 링크와 이것 저것을 보낼 항상 주위 아니에요 . 그래서 mods를 자동으로 풀다가 서버와 동기화되어 동시에 서버 데이터를 얻도록 프로그램 할 것이라고 생각했습니다.
저는 무료 FTP 호스트를 사용하고 있습니다.하지만 그 이유가 분명해질 것이라고 생각하지 않습니다.
기본적으로 전체 데이터 블록의 진행률을 표시하기 위해 진도 표시 줄과 이상적으로 레이블을 사용하고 싶습니다. 모든 개조는 함께 ... 1GB 이하 여야합니다.
그것은 무작위로 선택됩니다이 주장하기 전에
그것은 전체가 파일을 다운로드 할 수 있습니다 다운로드해야하는 파일을 다운로드하지 : 그러나, 나는 비동기 옵션에 대한 몇 가지 문제로 실행하는 것 완료 될
msgbox가 모든 항목의 다운로드를 완료했다는 메시지를 표시 할 때 프로그 레스 바가 50 % 찼을 수 있습니다. 진행 막대가 나는 BGworker의 싱크로를 실행할 때 진행,의 WebClient 동기 사용에 존재하지 않는의보고 이벤트로 인해 작동하지 않는 동안
그러나, 제대로 때마다 다운로드합니다. 그러나, 나는 기본적으로, 그래서 중요한의 종류 ....
인 진행률을보고 놓치게 :
- 이 구현하는 더 나은 방법이 있나요?
준비가되기 전에 작업하기 위해 필요한 마지막 청크입니다. 그래서 실제로 시도하고 싶습니다. 어떤 도움을 주셔서 감사합니다!
편집 : 코드 업데이트 : 모든
Public Function GetDownloadSize(ByVal URL As String) As Long
Dim request As Net.FtpWebRequest = DirectCast(Net.WebRequest.Create(URL), Net.FtpWebRequest)
request.Method = Net.WebRequestMethods.Ftp.GetFileSize
request.Credentials = New Net.NetworkCredential(dl_user, dl_pass)
Dim response As Net.FtpWebResponse = DirectCast(request.GetResponse(), Net.FtpWebResponse)
Dim fileSize As Long = response.ContentLength
Return fileSize
End Function
Private Sub btn_sync_Click(sender As Object, e As EventArgs) Handles btn_sync.Click
Dim cont As DialogResult = MsgBox("Continue? " + (total_dl_size/1000).ToString("N0") + " KB remain to be downloaded.", MsgBoxStyle.YesNo, "CAUTION!")
If cont = DialogResult.No Then
tb_warnings.AppendText("-ERR: User declined to synchronize files. Restart the application to sync.")
tb_warnings.AppendText(ControlChars.NewLine)
Label3.BackColor = Color.Firebrick
Return
End If
btn_sync.Enabled = False
btn_scan.Enabled = false
tb_warnings.AppendText("-Deleting outmoded/unused mods. Protected mods will be kept.")
For Each i As fdata_obj In deleted_files
My.Computer.FileSystem.DeleteFile(mc_dir + "\mods\" + i.name)
Next
tb_warnings.AppendText(ControlChars.NewLine)
tb_warnings.AppendText("-Deleting mod subdirectories to ensure no conflicts.")
tb_warnings.AppendText(ControlChars.NewLine)
For Each d In My.Computer.FileSystem.GetDirectories(mc_dir + "\mods")
My.Computer.FileSystem.DeleteDirectory(d, FileIO.DeleteDirectoryOption.DeleteAllContents)
Next
initialize_download()
End Sub
Private Sub initialize_download()
Dim wc As New System.Net.WebClient() ' SORRY, ASSUME THIS IS A PUBLIC VAR SO IT CAN BE REFERENCED ACROSS ITS OTHER METHODS
AddHandler wc.DownloadProgressChanged, AddressOf OnDownloadProgressChanged
AddHandler wc, AddressOf OnFileDownloadCompleted
Dim usr As String = "randouser"
Dim pass As String = "randopass"
For Each s In (From dl As fdata_obj In new_files Select dl_server + "/mods/" + mods_dir + "/" + dl.name).ToList
downloads.Enqueue(s)
Next
wc.Credentials = New Net.NetworkCredential(usr, pass)
Dim urix As String = downloads.Dequeue
Try
wc.DownloadFileasync(New Uri(urix), mc_dir + "\mods\" + IO.Path.GetFileName(urix))
Catch ex As Exception
MsgBox(ex.Message)
If tb_warnings.InvokeRequired = True Then
tb_warnings.Invoke(New tb_updater(AddressOf tb_update), "-ERR: Could not download file: " + urix, urix)
Else
tb_warnings.AppendText("-ERR: Could not download file: " + IO.Path.GetFileName(urix))
tb_warnings.AppendText(ControlChars.NewLine)
End If
end try
End Sub
Private Sub OnDownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
MsgBox("This is happening!")
total_dl = total_dl + e.BytesReceived
Dim percentage As Integer = (CType((total_dl/total_dl_size), Integer) * 100)
if percentage > 100 then
percentage = 100
endif
prog_update(percentage)
End Sub
delegate sub progress_update(byval prog as integer)
' POTENTIAL ISSUES HERE???????
private sub prog_update(byval prog as integer)
if progressbar1.invokerequired then
progressbar1.invoke(new prog_update(addressof progress),prog)
else
progressbar1.value = prog
Private Sub OnFileDownloadCompleted(ByVal sender As Net.WebClient, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If e.Cancelled Then
MsgBox(e.Cancelled)
ElseIf Not e.Error Is Nothing Then
MsgBox(e.Error.Message)
Else
if downloads.count > 0 then
Dim urix As String = downloads.Dequeue
Try
wc.DownloadFileasync(New Uri(urix), mc_dir + "\mods\" + IO.Path.GetFileName(urix))
Catch ex As Exception
MsgBox(ex.Message)
If tb_warnings.InvokeRequired = True Then
tb_warnings.Invoke(New tb_updater(AddressOf tb_update), "-ERR: Could not download file: " + urix, urix)
Else
tb_warnings.AppendText("-ERR: Could not download file: " + IO.Path.GetFileName(urix))
tb_warnings.AppendText(ControlChars.NewLine)
End If
End Try
End If
End Sub
지난 번 확인한 'WebClient'는 정상적으로 작동했습니다. 귀하의 코드를 보여주십시오. –
@VisualVincent # 1 : 멋진 사용자 이름, # 2 : 코드를 표시 할 수정 된 게시물.그 위임 함수 invoke 호출은 IDE의 이점을 가진이 코드를 다시 작성하고 형식을 매우 기억하지 않기 때문에 약간 꺼져있을 수 있습니다. 콜 템플릿이 원래 코드에서 맞는지 안심하십시오. –
** 1 : ** 고마워;) ** 2 : ** 좋아, 컴퓨터를 시작한 다음 코드를 사용해 보도록하겠습니다. –