我正试图在00:00自动发送电子邮件; 我使用过Quartz.net,但是中等可信环境(它是共享主机)存在问题。 I've read this on stackoverflow但是我不知道该怎么做。
另一个我无法创建Windows服务,因为它是共享主机。
还有其他办法吗?
答案 0 :(得分:0)
这不是一个很好的做法,但你可以做那样的事情(例如我使用的是MVC 4):
在Global.asax中,您可以尝试下一步:
public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
...//your current code
SendEmail();
SetUpTimer();
}
private static System.Threading.Timer _timer;
private void SetUpTimer()
{
TimeSpan timeToGo = DateTime.Now.AddDays(1).Date - DateTime.Now; //timespan for 00:00 tommorrow
_timer = new System.Threading.Timer(x => SendEmail(), null, timeToGo, new TimeSpan(1,0,0,0));
}
public void SendEmail()
{
//check if email was sent today if not send one
}
}