用streamreader读取,好像释放文件很慢,要30秒才能释放,文件很小才15行,不知道问题出在哪里。

SST_X 2019-07-02 01:46:43
Try
Dim sr As StreamReader = New StreamReader(taskStr1)
While foundDefectInTestFile = 1
line = sr.ReadLine()

If line Is Nothing Then
foundDefectInTestFile = 0
Exit While
Else

My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\logfile" & "\T2.txt", taskStr1 & vbCrLf, True, System.Text.Encoding.GetEncoding("GB2312"))

If InStr(UCase(line), "PROGRAM VALUE") > 0 Then
prgStr1 = Mid(line, line.IndexOf(Chr(34)) + 2, line.LastIndexOf(Chr(34)) - line.IndexOf(Chr(34)) - 1)
prgStr2 = prgStr1
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\logfile" & "\TEST2.txt", prgStr1 & " " & prgStr & vbCrLf, True, System.Text.Encoding.GetEncoding("GB2312"))

If prgStr1 = prgStr Then
foundDefectInTestFile = 0
'Exit For
Else
prgStr = prgStr2
End If

End If

End If
End While

sr.Close()
sr = Nothing

Catch ex As Exception
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "\logfile" & "\exception.txt", ex.ToString & vbCrLf, True, System.Text.Encoding.GetEncoding("GB2312"))

' Return
End Try
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SST_X 2019-07-05
  • 打赏
  • 举报
回复
谢谢大家。已经找到原因了。这个写在服务程序里,文件一直被监控,所以会被占用。在打开前加0.5秒延时就可以了。谢谢!
SST_X 2019-07-03
  • 打赏
  • 举报
回复
你好, 过程注释掉后测试了还是会占用很长时间,一样的报line = sr.ReadLine() 占用文件
wanghui0380 2019-07-03
  • 打赏
  • 举报
回复
一行一行读,一行一行处理。 这样你把,处理过程全注销掉,然后再告诉我们是几秒
hztltgg 2019-07-03
  • 打赏
  • 举报
回复
程序没有显式加入延迟的话,慢都是系统的原因,比如文件的网络流吗?是sd卡吗?文件手工打开关闭保存慢吗?
SST_X 2019-07-03
  • 打赏
  • 举报
回复
有人帮忙看一下吗?谢谢
SST_X 2019-07-03
  • 打赏
  • 举报
回复
这个是写在服务程序里的,有这个问题。正常程序测试是没有问题的

16,555

社区成员

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

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