Hai, 我在VS2012中使用控制台应用程序。 我想从MS Access DataBase更新员工信息(有超过70000条记录。 )。 因为服务器无法同时加载所有记录,我需要让我的进程休眠一分钟,它必须从它已经停止的记录开始。 /> for exmaple, 我使用的是for循环,
Hai, I am using a console application in VS2012. I want to update the employee information from the MS Access DataBase(More than 70000 records are there.). since the server is not able to load all the records at the same time, I need to make my process sleep for one minute and it has to start from the record it has stopped. for exmaple, I am using a for loop,
for(int i=0;;i++) { if(i<200) { while(dbReader.read()) { //Logic goes here // it gets the employee details one by one. } } else//when it has reached the limit { system.Threading.Thread.sleep(60000) } }现在在else部分,线程休眠一分钟,但我不知道如何从线程已经睡眠的记录中再次启动进程。 即 eg),循环进入第199个记录并睡眠一分钟。 然后它应该从第200个记录开始并在第399个记录之后休眠并继续...... 先谢谢!!!
Now in the else part the thread sleeps for one minute but I don't know how to start the process again from the record that the thread has slept. That is, eg),the loop goes till 199th record and sleeps for one minute. then it should start from the 200th record and sleeps after 399th record and goes on... Thanks in Advance!!!
推荐答案使用 MOD ,类似 if((i%200)=! 0)。然而,以这种方式编程是非常糟糕的做法。所以你可能想要一起寻找更好的解决方案。 祝你好运! use MOD, something like if((i % 200) =! 0). It is pretty bad practice to program this way however. So you might want to look into a better solution all together. Good luck!
首先,更新您的记录作为应用程序的一部分。第一种方法中的分钟间隔不适用于更新查询,如果您在每次注册的1分钟范围内添加此片段,您将在上次更新时继续。 部分将Select Value与TableName分开可以使用TOP 10 Hi, First of all, update your records as part of the application .Consol minute intervals in the first method did not work with the update query if you add into this piece in the range of 1 minute each registration you will continue where the last update. Partly to separate the Select Value From TableName can use the TOP 10
Hai, 我通过简单地删除If .. Else语句来解决自己/> ie), 我用过: for(int i = 0; i< 200; i ++) { while(dbReader.Read()) { //逻辑在这里。 System.Threading.Thread.sleep(60000)//它睡了1分钟。 继续; //每次睡眠后循环继续,直到达到极限。 /> } } Hai, I solved myself by simply removing the If.. Else statement i.e), I have used: for(int i=0;i<200;i++) { while(dbReader.Read()) { //Logic goes here. System.Threading.Thread.sleep(60000)//for 1 minute it sleeps. continue;//the looping continues after each sleep till it reaches the limit. } }
更多推荐
如何让进程睡眠并重新启动它?
发布评论