老师好!
分别在最新的开发版和商业版导入3个TXT文件,共17780行,商业版耗时8.88秒;开发版耗时159.77秒。
测试的数据源是sql本地外部数据源,环境、代码完全相同,为什么差异这么大?
尝试过重装开发版、删除项目Bin文件夹,压缩项目等,没有改善。这种情况可能是哪里的原因?
谢谢!
代码:
'''
Dim cn As Integer = 0 '预设导入文件个数
Dim count As Integer = 0 '导入总数
Dim str As String = "" '股piao名预设
Dim p As WinForm.ProgressBar '进度条预设
p = e.Form.Controls("ProgressBar1")
Tables("指数日线").StopRedraw()
Dim dlg As New OpenFileDialog
dlg.Filter = "TXT文件|*.TXT"
dlg.MultiSelect = True
If dlg.ShowDialog = DialogResult.Ok Then
count = dlg.FileNames.Length '导入个数
p.Minimum = 0
p.Maximum = count
p.Value = 0
Dim dt As Date = Date.Now
For Each file As String In dlg.FileNames
cn +=1 '文件个数
e.Form.Controls("Label3").text = "正在导入第 " & cn & "/" & count & " 只股piao:" & vbcrlf & FileSys.GetName(file)
e.Form.Controls("Label进度条百分比").text = Format(cn/count ,"Percent")
p.Value = cn
Application.DoEvents '代码即刻生效----耗时
Dim strs As String = FileSys.ReadAllText(file)
strs = strs.Trim().Replace(" ", ",").Replace(vbtab, ",").Replace(vblf,"")
Dim name As String = FileSys.GetName(file.SubString(0, file.length - 4))
Dim dr1 As DataRow = DataTables("自选股").Find("代码 = '" & name & "'")
Dim rs() As String = strs.Split(vbcr)
For i As Integer = 0 To rs.Length - 2
Dim cs() As String = rs(i).Split(",")
Dim dr As DataRow = DataTables("指数日线").Addnew()
dr("代码") = name
If dr1 Is Nothing Then
dr("名称") = name
Else
dr("名称") = dr1("名称")
End If
dr("日期") = cs(0)
dr("开盘价") = cs(1)
dr("最高价") = cs(2)
dr("最低价") = cs(3)
dr("收盘价") = cs(4)
dr("成交量") = cs(5)
dr("金额") = cs(6)
Next
GC.Collect '释放内存
Next
Dim tp As TimeSpan '计算耗时
tp = Date.Now - dt
e.Form.Controls("Label3").text = "正在导入 " & cn & " 只股piao," & "耗时 " & tp.TotalSeconds
End If
Tables("指数日线").ResumeRedraw()
msgbox("导入结束")
[此贴子已经被作者于2020/5/17 21:13:50编辑过]