2016-03-26 42 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

是的,但有没有办法冻结整个表格? @Werdna –

回答

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