I'd like to run a function every minute to achieve the following:
- Run function every minute
- Run MySQL command to get count
- Store the count into a variable
- Compare the result to old result every minute
- Create an If statement if number is not same to previous number.
Here is what I have:
private void Method()
{
int count = int.MinValue;
int prev_count = int.MinValue;
while (true)
{
//Get count from MySQL table
using (var conn = new MySqlConnection(ConnectionString.ConnString))
{
conn.Open();
using (var cmd = new MySqlCommand("select count(*) from table;", conn))
{
count = (int)cmd.ExecuteNonQuery();
}
}
if (count != prev_count)
{
prev_count = count;
}
}
}
My question is - is the correct way of coding this to compare the old number to new number? and also, how can I make this function run every minute?