private void timer1_Tick(object sender, EventArgs e)
        {
            threadOne = new Thread(new ThreadStart(ImportData));
            threadOne.IsBackground = true;
            threadOne.Start();
        }private void ImportData()
        {
            int errorFlowid = 0;
            string stmbnum = string.Empty;
            string tm = string.Empty;           
            try
            {
                
            }
            catch (Exception ex)
            {
     
            }
            finally
            {
                //if (threadOne != null)
                //{
                //    if (threadOne.IsAlive == true)
                //    {
                //        threadOne.Abort();                //    }
                //}                
            }
想问下大虾们,我这样写有没没问题,timer1_Tick这是一个时间控件,每隔一分钟执行一次,是不是执行一次就要中断线程一次?

解决方案 »

  1.   

    //if (threadOne != null)
      //{
      // if (threadOne.IsAlive == true)
      // {
      // threadOne.Abort();  // }
      //}   这段代码要还是不要
      

  2.   

    这样不好吧。。
    你是不是想让这个线程一直都要执行那就在那个ImportData方法里,用一个死循环来实现如private void ImportData()
      {
     while(true)
     {
      int errorFlowid = 0;
      string stmbnum = string.Empty;
      string tm = string.Empty;   
      try
      {
        
      }
      catch (Exception ex)
      {
        
      }
      finally
      {
      //if (threadOne != null)
      //{
      // if (threadOne.IsAlive == true)
      // {
      // threadOne.Abort();  // }
      //}   
      }
    }