程序假死

hackergoogle 2006-06-04 11:46:41
批量读取网页原文件时程序假死, 是不是要用多线程
Public Shared Function getHttpXml(ByVal mn As String) As String

Dim url As String = "http://www.123.com?mn=" & System.Web.HttpUtility.UrlEncode(mn, System.Text.UnicodeEncoding.GetEncoding("GB2312"))


Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(url)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpReq.Method = "GET"
httpReq.ContentType = "text/html; charset=utf-8"
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = False ' 获取或设置一个值,该值指示是否与 Internet 资源建立持久连接。

Dim reader As StreamReader = _
New StreamReader(httpResp.GetResponseStream, System.Text.Encoding.GetEncoding("GB2312"))
Return reader.ReadToEnd()


End Function
...全文
108 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hackergoogle 2006-06-04
  • 打赏
  • 举报
回复
可以加我qq吗,我是菜鸟,或者把你qq告诉我,???
lyfer 2006-06-04
  • 打赏
  • 举报
回复
这是一个类呀,多线程是一样的调用呀.WebBrowser是获取网页源码的最好的东东了(我是这么觉得的).我搞了几个月了,可以说是能用的办法都用过了.你试试看.
hackergoogle 2006-06-04
  • 打赏
  • 举报
回复
没看明白,你怎么不用多线程呢,怎么用WebBrowser???
lyfer 2006-06-04
  • 打赏
  • 举报
回复
我试验了二个月,发现最好用的还是webbrowser最好.呵呵.别忘记给分噢
如果是出现窗体不能移动或打开时,那就在你调用时加
My.Application.DoEvents()
我同时更新500个网页查询都没死过.不过CPU使用猛涨到10%-50%
内存一点一点被吃了,我去发个贴问一下.
lyfer 2006-06-04
  • 打赏
  • 举报
回复
记得imports system.net
lyfer 2006-06-04
  • 打赏
  • 举报
回复
算你运气好.哈哈,传说中的沙发我坐了.给你个我想了几个月才想通的东东.以前用别人发的会出现乱码,现在给你个类,你自己改改吧
Public Class HtmlSource
Private WithEvents myWebBrowser1 As WebBrowser
Public HtmlCode As String
Private key As String
Private song As String
Private FileType As String
Public Sub go(ByVal url As String, ByVal keys As String, ByVal songs As String, Optional ByVal FileTypes As String = ".mp3")
myWebBrowser1 = New WebBrowser
key = keys
song = songs
FileType = FileTypes
myWebBrowser1.Navigate(url)
End Sub


Private Sub myWebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles myWebBrowser1.DocumentCompleted
HtmlCode = myWebBrowser1.Document.Body.OuterHtml
Dim analyze As New Class1
'Dim downFile As New download
My.Application.DoEvents()
analyze.Dowork(HtmlCode, FileType, song)
Dim i As Integer
My.Application.DoEvents()
For i = 0 To UBound(analyze.tmp, 2)
My.Application.DoEvents()
If Trim(analyze.tmp(0, i)) <> "" Then
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.CurrentDirectory & "\tmp\" & song & ".leaf", Trim(analyze.tmp(1, i)) & "--" & Trim(analyze.tmp(0, i)) & "==" & Trim(analyze.tmp(2, i)) & vbCrLf, True)
End If
Next
'My.Application.DoEvents()
'downFile.DownLoadFile(Trim(analyze.tmp(0, 0)), "c:\下载的文件\" & song & FileType, key)
form1.lv.Items.Item(form1.lv.Items.IndexOfKey(key)).BackColor = Color.BurlyWood
analyze = Nothing
'downFile = Nothing
End Sub
End Class
lyfer 2006-06-04
  • 打赏
  • 举报
回复
229965669
加我.呵呵

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧