做了一个定时抓天气的线程, 在全局类里启动. 
一开始都好,但是不久(几个小时后)天气预报就不见了,线程莫名消失了 
请教高手,为什么 
线程程序 
public WeatherThread() 

        ThreadStart thr_start_func = new ThreadStart(threadProc); 
        fThread = new Thread(thr_start_func); 
        fThread.Name = "getWeather"; 
/*      fThread.IsBackground = true; 
        fThread.Start(); //starting the thread 
        flag = true; 
  */ 
}     public void trigger() 
    { 
        if (fThread.IsAlive) 
        { 
            fThread.Abort(); 
        } 
        else 
        { 
            fThread.IsBackground = true; 
            fThread.Start(); 
        } 
    }     public static void threadProc() 
    { 
        while (true) 
        { 
            try 
            { 
              Thread.Sleep(timeinternal * 1000); 
            } 
            catch (Exception) 
            { 
            } 
        }     } 
} 启动部分:global.asax 
    void Application_Start(object sender, EventArgs e) 
    { 
        // Code that runs on application startup 
        WeatherThread Wt = new WeatherThread(); 
        Wt.trigger(); 
    } 
    

解决方案 »

  1.   

     void Application_Start(object sender, EventArgs e)
            {
                // Code that runs on application startup 
                WeatherThread Wt = new WeatherThread();
                Wt.WeatherThread();
            }        Thread fThread = null;
            public void WeatherThread()
            {
                if (fThread == null)
                {
                    ThreadStart thr_start_func = new ThreadStart(threadProc);
                    fThread = new Thread(thr_start_func);
                    fThread.Name = "getWeather";
                }
            }        public static void threadProc()
            {
                while (true)
                {
                    try
                    {
                        //获取代码块
                    }
                    catch 
                    {
                        
                    }
                    finally
                    {
                        Thread.Sleep(timeinternal * 1000);
                    }
                }
            }
       
      

  2.   

    你的关键代码就给了这些?什么都没有做?:
    public static void threadProc() 
        { 
            while (true) 
            { 
                try 
                { 
                  Thread.Sleep(timeinternal * 1000); 
                } 
                catch (Exception) 
                { 
                } 
            } 
        }