private void checkConnectionThread(object obj)
{
//This thread runs every 5 minutes and checks to see when the last time we ran a query
//If it's been over 30 minutes, we close down the MySQL connection
while (true)
{
if (connection != null && connection.State == System.Data.ConnectionState.Open)
{
TimeSpan ts = DateTime.Now - lastQuery;
if (ts.Minutes > 30) {
//over 30 minutes, close it down
Logger.addMessage(Logger.LogType.Info, "30 minutes of inactivity have passed. Closing down MySQL connection.");
CloseConnection();
break;
}
}
//http://www.dotnetperls.com/sleep
//TODO: according to the above link, sleep does not use CPU cycles
//we need to make sure this is not significantly eating into CPU resources!
Thread.Sleep((60 * 5) * 1000);
}
//Logger.addMessage(Logger.LogType.Info, "checkConnectionThread closing down.");
//threads cannot be started up again, so we null this out, it will be opened back up later
staleConnectionThread = null;
}