Hi guys i have a problem with a block of code in a DLL i have written, the DLL receives Serial Data (NMEA) and then logs it to a file, it also holds in a dictionary (of string and date) the sentence header and the date and time it was last received).
I monitor the Task manager Thread-count and memory usage and it is going up quickly and after about 2.5 hours of running my program crashes with an out of memory error.
the code is below, if anyone can see where i am not releasing something or i am doing something fundamentally wrong please let me know as i am scratching my head at the moment, i added the code for serial data recieved and also the the managing of the dictionary (if a sentence isn't recieved for 5 minutes then it is removed from the list), finally there is a function to recover the date and time from the GPS NMEA Sentance:
any thoughts would be appreciated.
Thanks
Stu
I monitor the Task manager Thread-count and memory usage and it is going up quickly and after about 2.5 hours of running my program crashes with an out of memory error.
the code is below, if anyone can see where i am not releasing something or i am doing something fundamentally wrong please let me know as i am scratching my head at the moment, i added the code for serial data recieved and also the the managing of the dictionary (if a sentence isn't recieved for 5 minutes then it is removed from the list), finally there is a function to recover the date and time from the GPS NMEA Sentance:
VB.NET:
Private Sub SerialPort1_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Try
Dim ff As Boolean
If SerialPort1.IsOpen = True Then
Do
Dim incoming As String = SerialPort1.ReadLine()
If incoming Is Nothing Then
Exit Do
Else
If first = False Then
ff = Write_Data(incoming)
If ff = True Then
lastData = DateTime.Now
End If
Dim cursen As String
cursen = incoming.Substring(0, incoming.IndexOf(","))
addNMEA(cursen)
If cursen = "$GPZDA" Then
CurrentGPSDateTime = recoverDateTime(incoming)
End If
Else
first = False
End If
End If
Loop
End If
manageNMEAlist()
Catch
End Try
End Sub
Private Function recoverDateTime(ByVal NMEA As String) As Date
Try
Dim fields(), timeString As String
Dim timeArray() As Char
fields = NMEA.Split(",")
timeArray = fields(1).ToCharArray
timeString = fields(3) & "/" & fields(2) & "/" & fields(4) & " " & timeArray(0) & timeArray(1) & ":" & timeArray(2) & timeArray(3) & ":" & timeArray(4) & timeArray(5)
Return DateTime.ParseExact(timeString, "MM/dd/yyyy HH:mm:ss", Nothing)
Catch
Return #1/1/2001#
End Try
End Function
Private Function manageNMEAlist()
Try
Dim pair As KeyValuePair(Of String, Date)
For Each pair In currentNMEAList
If pair.Value < DateTime.Now.AddMinutes(-5) Then
currentNMEAList.Remove(pair.Key)
End If
Next
Return True
Catch
Return False
End Try
End Function
any thoughts would be appreciated.
Thanks
Stu