In asp.net forums2 or cs system, an email will be sent every few minutes, but if it is executed, the database server will restart.
Will cause the Send Email thread to die.
Reference code:
private void ScheduledWorkCallbackEmailInterval (object sender)
{
try {
// suspend the timer while we process emails
emailTimer.Change( System.Threading.Timeout.Infinite, EmailInterval );
// Send emails
//
Emails.SendQueuedEmails( (HttpContext) sender);
//Update anonymous users
//
Users.UpdateAnonymousUsers( (HttpContext) sender);
}
catch(Exception e) {
ForumException fe = new ForumException( ForumExceptionType.EmailUnableToSend, "Scheduled Worker Thread failed.", e );
fe.Log();
}
finally {
emailTimer.Change( EmailInterval, EmailInterval );
}
}
In fact, the code: emailTimer.Change(System.Threading.Timeout.Infinite, EmailInterval);
is not strong enough. In theory, if an error occurs during execution, it will be executed:
finally {
emailTimer.Change( EmailInterval, EmailInterval );
}
But, in fact, if the database server is restarted, the timer thread can die forever.
Manual solution: Restart the web app
or rewrite the code: emailTimer.Change( System.Threading.Timeout.Infinite, EmailInterval );
to: emailTimer.Change( EmailInterval * 2, EmailInterval );
can be solved
Other references:
msdn:
System.Theading.Timer.Change API: