日期:2014-05-17 浏览次数:20518 次
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
int seconds = 60;
aTimer.Elapsed += new ElapsedEventHandler(TimedEvent);
aTimer.Interval = seconds * 1000;
aTimer.Enabled = true;
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
//解决应用池回收问题
System.Threading.Thread.Sleep(5000);
string strUrl = "";//网站地址
System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
System.Net.HttpWebResponse _HttpWebResponse = (System.Net.HttpWebResponse)_HttpWebRequest.GetResponse();
System.IO.Stream _Stream = _HttpWebResponse.GetResponseStream();//得到回写的字节流
_HttpWebResponse.Close();
}
void TimedEvent(object source, ElapsedEventArgs e)
{
string appStartTime = ConfigurationManager.AppSettings["StartTime"];//执行时间 比如你这的08:00
string theNowTime = DateTime.Now.ToString("HH:mm");
if (theNowTime == appStartTime)
{
Method();//这里写你发邮件的方法
}
}