用计时器比较好吧 DoLoop(int start,int end){//do the loop }main(){ //... t1 = new Thread(new ThreadStart(DoLoop(0,50)));//t1 is a global Thread. t1.start(); timer.start();//timer is a Timer with an interval of 10000ms }timer_click(...){//occurs when the first 10000ms passed timer.Stop(); t1.Abort(); DoLoop(51,100); }
DoLoop(int start,int end){//do the loop
}main(){
//...
t1 = new Thread(new ThreadStart(DoLoop(0,50)));//t1 is a global Thread.
t1.start();
timer.start();//timer is a Timer with an interval of 10000ms
}timer_click(...){//occurs when the first 10000ms passed
timer.Stop();
t1.Abort();
DoLoop(51,100);
}
线程可以传参数吗?
{
p=p+t;
this.Character.Show(null);
string s="您已经连续使用电脑"+p+"分钟了,好男儿提醒您该注意保护一下您的眼睛了:)";
//精灵说话
Character.Speak(s,null);
int i=6000;
System.Threading.Thread.Sleep(i);
t++;
break;
}
bool exit = false;
private void button1_Click(object sender, System.EventArgs e)
{
dl d=new dl(this.DoLoop);
for (int i = 0; i<100; i++)
{
exit = false;
IAsyncResult ia = d.BeginInvoke(null,null);
ia.AsyncWaitHandle.WaitOne(10000,true);
exit = true;
System.Threading.Thread.Sleep(10);
}
}
private void DoLoop()
{
for (int i = 0; i<100000; i++)
{
if (exit)
{
return;
}
System.Threading.Thread.Sleep(10);
}
}