日期:2014-05-18  浏览次数:21535 次

c#暂停循环
for(i=0;i<10000;i++)
{
 lable1.text=i.toString();
}
如果做到点击暂停, 再点击从暂停处开始?

------解决方案--------------------
AutoResetEvent autoEvent = new AutoResetEvent(false); 
bool threadSwitch = false; 

button_onclick() 
{ 
if(button.Text.Equal("暂停")) 
{ 
threadSwitch = true; 
button.Text = "开始"; 
} 
else 
{ 
button.Text = "暂停";
threadSwitch = false; 
autoEvent.Set(); 
} 
} 


for(i=0;i <10000;i++) 
{ 
lable1.text=i.toString(); 
if(threadSwitch) 
{ 
autoEvent.WaitOne(); 
} 
} 
红色的忘记加了。