I have a function that has event handler. It is reading gps position and everytime position is read I put data in the database, problem is that I have like 3 inputs for one sec.
How can I make some part of code to be proceeded every 5 sec for example?
I have tried to do timer_tick, but I don’t know how to do it because this is function with event handler.
Here is my function:
private void GPS_PositionReceived(string Lat, string Lon)
{
arrLon = Lon.Split(new char[] { '°', '"' }, StringSplitOptions.RemoveEmptyEntries);
dblLon = double.Parse(arrLon[0]) + double.Parse(arrLon[1], new System.Globalization.NumberFormatInfo()) / 60;
deciLon = arrLon[2] == "E" ? dblLon : -dblLon;
arrLat = Lat.Split(new char[] { '°', '"' }, StringSplitOptions.RemoveEmptyEntries);
dblLat = double.Parse(arrLat[0]) + double.Parse(arrLat[1], new System.Globalization.NumberFormatInfo()) / 60;
deciLat = arrLat[2] == "N" ? dblLat : -dblLat;
... //code
}
I want this part of the code to be used every 5 sec.
Oh yes and this is the event handler:
GPS.PositionReceived += new NmeaInterpreter.PositionReceivedEventHandler(GPS_PositionReceived);
I think what you are trying to say is that your method is being called 3 times a second, and in reality you only want it to be called every 5 seconds? Correct.
If so, store a
variable, and everytime you write to the database, update this timestamp.
Then you can use a check like
As the first line of your method.