My Console app is reading huge volume of data from text files and those will be saved to a DB. For this purpose, I am storing the data into a DataTable and I want to dump this DataTable to a DB every 5 minutes (If I want to dump the whole data at once, then I have to fill the DataTable with whole set of data , and in that case I am getting OutOfMemoryException).
public void ProcessData()
{
    string[] files=File.ReadAllLines(path)
    foreach(var item in files)
    {
        DataRow dtRow= dataTable.NewRow();
        dtRow["ID"]= .... //some code here;
        dtRow["Name"]= .... //some code here;
        dtRow["Age"]= .... //some code here;
        var timer = new Timer(v => SaveData(), null, 0, 5*60*1000);
    }
}
public void SaveData(string tableName, DataTable dataTable )
{
    //Some code Here
    //After dumping data to DB, clear DataTable
    dataTable.Rows.Clear();
}
What I wanted here is, the code will continue to fill the DataTable, and every 5 minute it will call SaveData() method. This will continue to run till all files has processed.
However, I have seen that, when the SaveData() method is called , it is executing for 4-5 times. Sometimes, it has bot called in every 5 minute.
I am not getting how to proceed here. How to fix this ? Can any other approach be used here ? Any help is appreciated.
 
     
     
    