对于循环需要暂停并在完成一些更新后继续,再次循环应该从它暂停的点继续 [英] For Loops Needs To be paused and continued after some updation are done ,again loop should continue from the point it's paused

查看:82
本文介绍了对于循环需要暂停并在完成一些更新后继续,再次循环应该从它暂停的点继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Senario:



有一个包含预定日期和时间的项目的列表,我们需要根据列表进行迭代预定的日期和时间。我们正在给用户选择更新或重新安排非迭代列表项的日期和时间。



的事情是我们需要暂停迭代并继续进行最新更新。



ex:list



step1:< br $>


for(int i = 0; i< = items.count; i ++)

{

if( process.ispaused)

{

打破循环; ///这里用户必须能够更新当前列表。



}



else

{

遍历商品



}



}



我们正在做的是:我们正在使用后台工作程序。




在doworker事件中我们无法暂停循环。请帮我解决问题。我们无法暂停线程。

Senario:

there is a list consisting of items with scheduled date and time,we need to iterate through the list based on the scheduled date and time.Mean while we are giving the user a choice to update or re-schedule date and time for non iterated list items.

thing is that we need to pause the iteration and continue along with latest updates.

ex: list

step1:

for(int i=0;i<=items.count;i++)
{
if(process.ispaused)
{
break the loop; ///here user must be able to update the current list .

}

else
{
iterate through items

}

}

what we are doing is : we are using background worker process .


in doworker event we are not able to pause the loop.please help me out to come up with the issue. we are not able to pause the thread.

推荐答案

暂停循环的唯一方法是使用Thread.Sleep然后当睡眠结束时,检查它是否是假设保持睡眠与否。总的来说,你的设计听起来不对。您只需要花一点时间来刷新列表,不应该经常这样做,以至于您需要停止更新以允许添加新条目。
The only way to pause a loop is to use Thread.Sleep and then when the sleep ends, check if it's supposed to keep sleeping or not. Overall, your design sounds wrong to me. You should only take a moment to refresh a list, you should not do that so constantly that you need to stop updating to allow new entries to be added.


这篇关于对于循环需要暂停并在完成一些更新后继续,再次循环应该从它暂停的点继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆