以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]怎样多线程获取网络数据 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=172437) |
||||
-- 作者:天一生水 -- 发布时间:2021/10/12 22:10:00 -- [求助]怎样多线程获取网络数据 老师好! 下面的代码逐行获取单日 1000只股票数据,耗时150秒,怎样采用多线程获取? 请老师给改个例子学习一下,谢谢! 代码: \'\'\' Dim sstr As String = "" \'错误记录 Dim dm,dm1 As String \'沪深冠字 Dim _sr As String = Format(e.Form.Controls("DateTimePicker1").value , "yyyyMMdd") \'起始日期=结束日期 Dim _zr As String = Format(e.Form.Controls("DateTimePicker1").value , "yyyyMMdd") \'结束日期 Dim cn As Integer = 0 \'预设导入股票个数 Dim dt As Date = Date.Now Dim str As String = "" \'股票名预设 Dim count As Integer = Tables("沪深A股").rows.count \'股票个数 DataTables("沪深A股").ResumeRedraw Dim obj_down As New System.Net.WebClient() DataTables("沪深A股").StopRedraw For Each dr As DataRow In DataTables("沪深A股").DataRows \'遍历行,根据代码获取数据,起始时间与结束时间相同,仅获取单日数据 If dr.IsNull("代码") = False Then dm = dr("代码") If dm >= 600000 Then dm1 = "0" & dm \'沪市 Else dm1 = "1" & dm \'深市 End If End If try Dim data As String = obj_down.DownloadString("http://quotes.money.163.com/service/chddata.html?code=" & dm1 & "&start=" & _sr & "&end=" & _zr & "&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP") data = data.Replace(vblf,"").Replace("\'","\'\'") Dim rs() As String = data.Split(vbcr) str = dm cn +=1 \'股票个数 \'For i As Integer = 1 To rs.Length - 2 \'首行是标题 Dim cs() As String = rs(1).Split(",") If cs.Length = 15 Then dr("日期") = cs(0) dr("今日开盘") = cs(6) dr("今日涨跌幅") = cs(9) End If \'Next Catch ex As Exception sstr &= dm & "," \'出错个数 End Try Next DataTables("沪深A股").ResumeRedraw Dim tp As TimeSpan tp = Date.Now - dt e.Form.Controls("Label运行提示").text = "正在下载 " & cn & "/" & count & " 只股票:" & vbcrlf & "耗时 " & tp.TotalSeconds
|
||||
-- 作者:有点蓝 -- 发布时间:2021/10/12 22:56:00 -- 参考:http://www.foxtable.com/mobilehelp/topics/3268.htm 代码里不要使用DataTables,全部改为使用SQLcommand操作数据库 |
||||
-- 作者:bobatfoxtable -- 发布时间:2021/10/13 11:10:00 -- 可以用Go语言开发接口 |
||||
-- 作者:天一生水 -- 发布时间:2021/10/13 11:37:00 -- 谢谢朋友,还没有接触过~ |