I am starting a project where the program will poll a database every x seconds (say 10) and get rows that fall within a certain time period (based on a datetime field). This could be 0 - 40 rows or so for each poll. These rows will then be put into another database after some business logic is run. My initial thought is there will be some logic that puts the rows (converted to objects) in a collection, like a list, and the list has an event that gets fired when an item is added. Finally, the row is put in the dest. DB.
I'm thinking about it like this:
PsuedoCode
private List<Person> PersonList;
public MyClassConst()
{
PersonList = new List<Person>();
PersonList.AddingEvent += HandleAddingEvent;
}
void HandleAddingEvent(...)
{
// run business logic/rules
// insert/update row in destination DB
}
void Timer_Elapsed()
{
// query and convert to Person objects
var personData = _personDao.GetPersons();
for(int i=0; i< personData.Count; ++i)
{
PersonList.add(personData[i]);
}
}
My concern is that if there are 40 rows, the event will be triggered 40 times, which doesn't seem ideal. How would I disable the event until after all the 40 objects have been added to the list.
if there is a better solution than using a list to do this, by all means, please share.