A c# application is writting on a MS SQL DB table at several times.
the records of this table must be read and procceessed by another c# application.
At the moment I have implemented I Threading timer which looks (every 2 secs) if the table has rows and proccess the data:
System.Threading.Timer checkTimer;
checkTimer = new System.Threading.Timer(Callback, null, 2000, 500);
private void InitSQLCon()
{
Con = new SqlConnection(ConectionString);
Con.Open();
}
private void Callback(Object state)
{
string queryString = "Select [Wi_Customer ID],[Wi_License_plate_ID] from " + Properties.Settings.Default.Table1 + " where Wi_Car_Rfid='" + s + "'";
SqlCommand command = new SqlCommand(queryString, Con);
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
///...make neccessary operations
}
}
My problem is that the current implementation isn't effecient.
Checking the table with a timer is resource consuming.
I would like to do it in an event driven way.
Ideally I would like to implement and event handler raised by the add record to table1
event.
If this possible (since I have never implemented an event handler) I would appreciate any feedbacks on how this can be done.