【发布时间】:2017-05-04 19:11:53
【问题描述】:
我正在尝试每天在特定时间发送一封电子邮件, 但似乎 System.Threading.TimerCallback 中的函数(void SomeMethodRunsAtSpecificTime(object o)) 不起作用。
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
double TimeOfExecution = 14;
DateTime now = DateTime.Now;
DateTime today7am = now.Date.AddHours(TimeOfExecution);
DateTime next7am = now <= today7am ? today7am : today7am.AddDays(1);
System.Threading.TimerCallback callback = new
System.Threading.TimerCallback(SomeMethodRunsAtSpecificTime);
var timer1 = new System.Threading.Timer(callback, null, next7am - DateTime.Now, TimeSpan.FromHours(24));
}
void SomeMethodRunsAtSpecificTime(object o)
{
//Sending email from someone to someone(this function has no problem)
}
【问题讨论】:
标签: c# asp.net multithreading timer