读取后文件未更新

时间:2018-12-14 16:53:48

标签: vb.net

我有一个运行多次的进程,并使用一个数据文件将信息从一个传递到下一个。此数据并不总是得到更新和传递。

这是代码。

Dim FileContent() As String = System.IO.File.ReadAllLines(iFile)
For line As Integer = 0 To UBound(FileContent)
    TempString = FileContent(line)

    If TempString.Contains("BegYear") Then
        BegYear = CInt(TempString.Substring(9,))

    ElseIf TempString.Contains("EndYear") Then
        EndYear = CInt(TempString.Substring(9,))
    End If

Next line

' Update all the run dates for the next run in the text file
BegYear2 = BegYear + TimeLength
EndYear2 = EndYear + TimeLength
FileContent = System.IO.File.ReadAllLines(iFile)
FileContent(LBound(FileContent)+2) = "BegYear: " & BegYear2
FileContent(LBound(FileContent)+3) = "EndYear: " & EndYear2
System.IO.File.WriteAllLines(iFile,FileContent)

正在发生的情况是运行间隔为15秒,但是由于某种原因,BegYear行没有得到更新,而EndYear行却得到了更新。完成此过程后,是否可以清除所有内存或关闭文件?

顺便说一句,如果它运行20次,则前10个(或大约)工作正常。后来才出现问题。

0 个答案:

没有答案
相关问题