杞人忧天上掉下个林妹妹

穿越旷野的妹妹啊,慢些走;请不要用你的沉默告诉我,你不回头!

导航

C#中线程的应用

使用计时器进行计时

在一个窗体中声明一个线程对象
private Thread trdTrans = null;  

//计时器事件  
private void tmrDataTrans_Tick(object sender, System.EventArgs e)  
{      
   if( (trdTrans == null) || (trdTrans.ThreadState == ThreadState.Stopped) ) 
   {    
      trdTrans = new Thread(new ThreadStart(Startup));   
      trdTrans.Start();       
   }  
}

完全使用线程类

private Thread trdTrans = null;  
private bool Run=false;
public void Start()
{
      trdTrans = new Thread(new ThreadStart(Startup));   
      Run=true;
      trdTrans.Start(); 

}
private void Startup()
{
   while(Run)
   {
      thread.Sleep(1000);
   }
}
public void Stop()
{
   Run=false;
   thread.Sleep(100);
   trdtrans.Abrot();
}

posted on 2006-05-26 11:27  杞人  阅读(304)  评论(0编辑  收藏  举报