Ask a questionAsk a question
 

AnswerSlow thread while counting lines i/o

  • Monday, October 19, 2009 9:22 AMbochelie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    Hallo,
    I have a problem with a thread that i made. I have a form which of course runs on his own thread. From that place i want to start a new thread which will count some lines in a tab separated file. The reason why i start a new thread is because i don’t want the counting of the lines to slow other processes on my form. Unfortunately this happens anyway.

    I still can’t find out why the thread slows my other processes in the original form. The whole idea of a new thread is to avoid slowlines on other processes....

    Does someone have any idea?


       Public Sub LogThreadStart()
            'prepare/start new thread to log data
            'this way the slowlines of datalogging don't interupt the other processes.
    
            Dim startThreadLogSub As New System.Threading.Thread(AddressOf Me.ThreadLogSub)
            startThreadLogSub.Priority = Threading.ThreadPriority.Normal
            startThreadLogSub.Start(Me.DsDTSettings.Tables("dtDataLogSettings").Rows(0).Item("clmnLogFileName").ToString())
    
        End Sub
        Private Sub ThreadLogSub(ByVal Filnm As String)
            'start LogFrmDLL.LogDataNow 
            LogFrmDLL.LogDataNow(Me.QueueDataLog, Filnm, MaxLogFileLinesSurpassed)
        End Sub
    
    
    
    Public Module LogFrmDLL
    
        Public Sub LogDataNow(ByVal QueueLog As Queue, ByVal FileNameDataLog As String, ByRef MaxLogFileLinesSurpassed As Boolean)
    
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ' if the logfile >= then x lines then 
            ' change MaxLogFileLinesSurpassed to true, in that way a new file 
            ' is created when in HdForm.TimerDataLog_Tick
            Using FileReader2 As New Microsoft.VisualBasic.FileIO.TextFieldParser(FileNameDataLog)
                FileReader2.Delimiters = New String() {"    "}
                While Not FileReader2.EndOfData
                    FileReader2.ReadLine()
                    If FileReader2.LineNumber >= 70000 Then MaxLogFileLinesSurpassed = True
                End While
            End Using
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
        End Sub
    
    End Module

Answers

  • Wednesday, October 28, 2009 8:50 AMbochelie Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Done. Just read the whole file in a string and then split ect. Don't use the while loop.
    • Marked As Answer bybochelie Wednesday, October 28, 2009 8:51 AM
    •  

All Replies