定时执行一段代码
Global.asax void Refresh()
{
while (true)
{
System.Web.HttpContext current = System.Web.HttpContext.Current;
if (current != null)
{
System.Web.HttpContext.Current.Application..........
}
Thread.CurrentThread.Join(1000 * 60 * 1);//阻止 分钟
}
}
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
thread = new Thread(new ThreadStart(Refresh));
thread.Name = "更新特价数据";
thread.Start();
}
执行的代码中需要用到 Application,但System.Web.HttpContext.Current永远为空,除了在Global.asax中定时执行外,还有什么方法?
Global.asax void Refresh()
{
while (true)
{
System.Web.HttpContext current = System.Web.HttpContext.Current;
if (current != null)
{
System.Web.HttpContext.Current.Application..........
}
Thread.CurrentThread.Join(1000 * 60 * 1);//阻止 分钟
}
}
void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
thread = new Thread(new ThreadStart(Refresh));
thread.Name = "更新特价数据";
thread.Start();
}
执行的代码中需要用到 Application,但System.Web.HttpContext.Current永远为空,除了在Global.asax中定时执行外,还有什么方法?
解决方案 »
- C# wimform 实现等待窗口
- DataBinding:“System.Data.DataRowView”不包含名为“CartID”的属性。
- IrisSkin2.dll的一些问题
- 如何更改ListBox的选中项的值?
- OleDB 方式导出Excel模板,数据如何从第一行开始?
- C#调用wininet时FtpCreateDirectory出错
- Oracle数据库提出A component named Field58 already exists!!(帖子里有建表语句,查询语句)
- 怎样引用第三方的dll
- 急求:c#中的跳转语句.谢谢大家了!
- C#中的语句不会写???
- 请各位好心人帮帮忙,遇到分页修改单条数据有误
- C#文字研究助手 求代码参考
{
Application[""]="";
//在 Refresh中使用
thread = new Thread(new ThreadStart(Refresh));
thread.Name = "";
thread.Start();
}
Application_Start 调用时,Request 没有创建
这个最好定义在while外.