Global.asax
void Application_Start(object sender, EventArgs e)
{ //定时更新关键字广告的搜索时间
CommonDAL.AdsImgTaskBegin();
}
==============
//另外一个类的代码 //间隔更新关键字广告的搜索时间,达到部分模块随机搜索功能
public static void AdsImgTaskBegin()
{
int sendsecend = 360;
System.Timers.Timer t = new System.Timers.Timer(1000 * sendsecend);//每1小时更新一个
t.Elapsed += new System.Timers.ElapsedEventHandler(RunUpdateSearchAdsImgTime);
t.AutoReset = true;
t.Enabled = true;
t.Start();
GC.KeepAlive(t);
}
public static void RunUpdateSearchAdsImgTime(object sender, System.Timers.ElapsedEventArgs e)
{
if (SqlHelper.UpInfo_int("ThreadingUpAdsImgSearchTime", null) <= 0) //更新数据库
{
string strErrorMessage = string.Empty; string strPage = HttpContext.Current.Request.Url == null ? string.Empty : HttpContext.Current.Request.Url.ToString();
string strIP = UserUtil.GetClientIP(); // 在出现未处理的错误时运行的代码----通常只处理该异常就好 strErrorMessage = "站点定时更新关键字广告表的搜索时间失败"; GlobalDataDAL.RecordSysLog(strPage, strErrorMessage, strIP, 2); }
}
为什么程序都不定期执行这个RunUpdateSearchAdsImgTime事件呢?无论重启IIS。或重新编译网站。均不会触发这个事件。数据库都没有改变。
已经确定SqlHelper.UpInfo_int()这个没有问题
站点利用System.Timer.Timer的时间戳进行定期执行RunUpdateSearchAdsImgTime事件。
大家针对定期执行某个方法。有何高见。可继续。WebService或Windows服务也行。不过现在我做的这个就不改了。以后有时间再让人改吧