首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c#暂停循环,该如何解决

2012-01-01 
c#暂停循环for(i0i10000i++){lable1.texti.toString()}如果做到点击暂停, 再点击从暂停处开始?[解决

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(); 


红色的忘记加了。

热点排行