2016-03-26 13 views
0

私はソースファイルダウンローダ-latestを偽造作っていますフリーズと私はしばらくの間(10〜15秒)Vb.netは - HTMLDocumentのは、フォーム

するためのフォームがフリーズリンクを取得しようとすると、これは私のコードです:

Private Function SourceForgeGetDirectUri(Uri As String) As String 
    Dim doc As HtmlDocument = New HtmlWeb().Load(Uri) 'loads the website 
    Dim aHref As HtmlNode = doc.DocumentNode.SelectSingleNode("//a[@class='direct-download']") 'finds the a href of the direct download 
    Dim DirectLink = aHref.GetAttributeValue("href", "") ' gets the link 

    Return DirectLink 
End Function 

このフリーズを停止するにはどうすればよいですか?

+0

を、それがタスクを完了した後に、それは再び通常のように動作しますか? – Werdna

+0

はい、フォーム全体をフリーズしない方法はありますか? @ヴェルドナ –

答えて

0

私は、BackgroundWorkerのコードを使用してこれを解決:

Private Sub SourceForgeDownload_DoWork(sender As Object, e As DoWorkEventArgs) Handles SourceForgeDownload.DoWork 
    SourceForgeDirectLink = SourceForgeGetDirectUri("https://sourceforge.net/projects/openofficeorg.mirror/files/latest/download") 
    If CheckBox1.Checked = True Then 
     Dim wc As New WebClient() 
     AddHandler wc.DownloadProgressChanged, AddressOf wc_Changed 
     AddHandler wc.DownloadFileCompleted, AddressOf wc_Completed 
     wc.DownloadFileAsync(New Uri(SourceForgeDirectLink), My.Computer.FileSystem.CurrentDirectory + "filename.exe") 
    End If 
End Sub 
関連する問題