private static System.Threading.Timer timer;
private const int interval = 1000 * 60 * 2;
protected void Application_Start(Object sender, EventArgs e)
{
if (timer == null)
   timer = new System.Threading.Timer(new System.Threading.TimerCallback(ScheduledWorkCallback),sender, 0, interval);
}       
private void ScheduledWorkCallback (object sender)
{
  Directory.Delete(Server.MapPath("temp"),true);
}一有IO操作就报w3wp.exe错误,这是为什么呀,如果单独是数据库操作则没问题,IO操作写在Application_Start里也没问题,唯独写在timer的过程里就不行,我是想定时清空临时目录

解决方案 »

  1.   

    存在着,我看着这个temp呢,就是删不了,报错,加判断也没用,一样错
      

  2.   

    是的,楼上的说的是,应该先
    if(Directory.Exists(Server.MapPath("temp")))
    {
    Directory.Delete(Server.MapPath("temp"),true);
    }
      

  3.   

    你打印出来Server.MapPath("temp")看是什么,路经正确吗?
    另外,里面的文件程序有在使用的马?
      

  4.   

    加判断一样的错,我试了,如果是
    Directory.Delete(@"E:\abc\temp\",true);这样可以删掉
    Directory.Delete(Server.MapPath("temp"),true);这样出现致命w3wp.exe错误
      

  5.   

    是不是只有Request才可以用Server,Global执行不可能产生Request
      

  6.   

    线程里面是不能使用Request的,再application start的时候可以使用