我在委托的函数中调用  System.Web.HttpContext.Current.Server  就会报错.而且是Web异常.问题就在于没有找到Server 对象,请知道的朋友告诉我下
 private System.Threading.Timer UpdateTimer = null;
    public void Start()
    {
        if (UpdateTimer == null)
        {  
            UpdateTimer = new System.Threading.Timer(new TimerCallback(UpdateTimerCallback), null, Interval, Interval);
           
        }
    }    
    private void UpdateTimerCallback(object sender)
    {
        
        if (Interlocked.Exchange(ref _IsRunning, 1) == 0)
        {
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(System.Web.HttpContext.Current.Server.MapPath("emailInfo.xml"));
   
         try
            {              
                string sql = "select * from EmailSendNote where emailType=1 ";
                DataSet ds = sh.ExecuteDataSet(sql);
                if (ds.Tables[0].Rows.Count<1)

解决方案 »

  1.   

    我用
     if (System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Server == null)
            {
                return;
            }
    作判断,结果执行了return
      

  2.   

    HttpContext.Current 属性
    为当前 HTTP 请求获取或设置 HttpContext 对象。 你这里没有请求,不能使用  HttpContext 对象
      

  3.   

    你可以在aspx.cs里启动,传参数进去,或者试试通过Application对象找文件路径
      

  4.   

    Application 对象也没有........
      

  5.   

    你的代码在哪调用的?类里?
    那就加一个属性,将当前的Application或者System.Web.HttpContext.Current传递进去
      

  6.   

    我在Global.asax 里调用 的
     private System.Threading.Timer UpdateTimer = null;
        private int _IsRunning;
        SqlHelper sh = new SqlHelper();
        void Application_Start(object sender, EventArgs e)
        {        
            // 在应用程序启动时运行的代码    
            
            UpdateTimer = new System.Threading.Timer(new System.Threading.TimerCallback(UpdateTimerCallback), null, 1000, 1000);
            
        }
        private void UpdateTimerCallback(object sender)
        {
            
            if (System.Threading.Interlocked.Exchange(ref _IsRunning, 1) == 0)
            {
                System.Web.HttpContext.Current.Application["sentType"] = "aaa";
                try
                {
                    string sql = "select * from EmailSendNote where emailType=1 ";
                    System.Data.DataSet ds = sh.ExecuteDataSet(sql);
                    if (ds.Tables[0].Rows.Count < 1)
                    {
      

  7.   

     问题已解决 ,  谢谢了net_lover