I have the following piece of code, that runs a "select" on certain table that needs to be monitored every 200 miliseconds
timerMonitoreoOrdenes = new System.Timers.Timer(FRECUENCIA_MONITOREO_ORDENES);
timerMonitoreoOrdenes.Elapsed += new ElapsedEventHandler(timerMonitoreoOrdenes_Elapsed);
timerMonitoreoOrdenes.Enabled = true;
timerMonitoreoOrdenes.AutoReset = true;
In the timerMonitoreoOrdenes_Elapsed
method I run a stored procedure that returns a DataSet
and for each row I am creating a new Object that is stored in memory Queue
The program is designed to be running all the time (like a windows service) but after the programs runs for a few hours I am getting this exception
System.OutOfMemoryException:
in System.Threading.ExecutionContext.CreateCopy()
in System.Threading._TimerCallback.PerformTimerCallback(Object state)
The reason that I am doing this like this is becase there is an external program that is inserting records on the DB with status=0 and I need to take those records, process them and set the status=1. There are some Thread that are taking records from the Queue
Is important to mention that This is for a REAL-TIME-TRADING application that 1 second delay in the information is too high
- I want to know if the System.OutOfMemoryException is being thrown because of the timer autoreset ?
- Should I create a Thread or use Thread.Sleep instead of a Timer to check for certain records that were inserted by another process ?