int count = 0;
System.Timers.Timer timer = null;
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
timer = new System.Timers.Timer(3600000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.AutoReset = true;
Application.Lock();
Application["timer"] = DateTime.Now;
Application.UnLock();
timer.Enabled = true;
} void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Application.Lock();
DateTime dtNow = Convert.ToDateTime(Application["timer"]);
dtNow.AddSeconds(3600); if (dtNow != null)
{
if (DateTime.TryParse(dtNow.ToString(),out dtNow))
{
int hoursNow = dtNow.Hour;
if (hoursNow.Equals(21)&&count.Equals(0))
{
count++;
//这里可以写你需要执行的任务,比如说,清理数据库的无效数据或增加每个用户的积分等等
}
else if (hoursNow.Equals(1))
{
count = 0;
}
}
}
Application.UnLock();
}
System.Timers.Timer timer = null;
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
timer = new System.Timers.Timer(3600000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.AutoReset = true;
Application.Lock();
Application["timer"] = DateTime.Now;
Application.UnLock();
timer.Enabled = true;
} void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Application.Lock();
DateTime dtNow = Convert.ToDateTime(Application["timer"]);
dtNow.AddSeconds(3600); if (dtNow != null)
{
if (DateTime.TryParse(dtNow.ToString(),out dtNow))
{
int hoursNow = dtNow.Hour;
if (hoursNow.Equals(21)&&count.Equals(0))
{
count++;
//这里可以写你需要执行的任务,比如说,清理数据库的无效数据或增加每个用户的积分等等
}
else if (hoursNow.Equals(1))
{
count = 0;
}
}
}
Application.UnLock();
}
一般本地可以,发布不可以主要就是几个方面导致的
你应该依次派查
1、是否有路径问题
2、是否有配置文件问题
3、数据库连接是否与你机器的路径有关了,
4、环境问题:
这里又分,程序运行的必要环境,开发环境 发布
路径