foreach() problem
-
hello , i want to have some delay in the execution foreach loop. i actually want to display different web pages in internet explorer(embeded in my application). but foreach loop just went through very quickly and just show me the last page. have used sleep(); but this just do the same. have also used Timer, but not working. can someone guide me on this, in case of foreach() loop. ASIM Asim
-
hello , i want to have some delay in the execution foreach loop. i actually want to display different web pages in internet explorer(embeded in my application). but foreach loop just went through very quickly and just show me the last page. have used sleep(); but this just do the same. have also used Timer, but not working. can someone guide me on this, in case of foreach() loop. ASIM Asim
can we see the code...
"When the only tool you have is a hammer, a sore thumb you will have."
-
hello , i want to have some delay in the execution foreach loop. i actually want to display different web pages in internet explorer(embeded in my application). but foreach loop just went through very quickly and just show me the last page. have used sleep(); but this just do the same. have also used Timer, but not working. can someone guide me on this, in case of foreach() loop. ASIM Asim
From your description, it sounds like the reason your code doesn't work as expected is because the loop is running on the server and is thus starting over each time. I have two that you could try, both are client-side javascript: Window.setTimeout(code, delay) - A string of script to execute after millisecods delay has expired. You could call a function that keeps track of which page to display next. setTimeout fires only once, so your function will have to reregister call setTimeout() as well. Window.setInterval(code, interval) Window.setInterval(func, interval, args...) - Similiar to setTimeout, but repeats perpetually. The second overload may be the most appropriate for your problem. HTH
-
hello , i want to have some delay in the execution foreach loop. i actually want to display different web pages in internet explorer(embeded in my application). but foreach loop just went through very quickly and just show me the last page. have used sleep(); but this just do the same. have also used Timer, but not working. can someone guide me on this, in case of foreach() loop. ASIM Asim
Remember that
Thread.Sleep()
takes time in milliseconds. This executes on the current thread, so there's no reason thatThread.Sleep(30000)
shouldn't sleep for 30 seconds.Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
-
can we see the code...
"When the only tool you have is a hammer, a sore thumb you will have."
here it is object o=null; foreach(Match m in Matchescollection) { awxWebBrowser.navigate("http://192....."+m.value().tostring(),ref o,ref o,ref o,ref o) } here Matchescollection contains all the links i.e. and on each match in the collection i want the Internet explorer to go to that link. for this i have used the m.value() concatenated with the IP of the site (here IP is permanent). this is what i want to have. now the problem is once it enters loop it just get all the values and concat them and then , as there is no time for displaying page, it just shows the last page. i.e. last link's page. i just want to have this delay so that it shows a page then again uptill the last page. ASIM Asim
-
Remember that
Thread.Sleep()
takes time in milliseconds. This executes on the current thread, so there's no reason thatThread.Sleep(30000)
shouldn't sleep for 30 seconds.Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
? MEAN WHAT ? i have wrote the code below. here it is object o=null; foreach(Match m in Matchescollection) { awxWebBrowser.navigate("http://192....."+m.value().tostring(),ref o,ref o,ref o,ref o) } here Matchescollection contains all the links i.e. and on each match in the collection i want the Internet explorer to go to that link. for this i have used the m.value() concatenated with the IP of the site (here IP is permanent). this is what i want to have. now the problem is once it enters loop it just get all the values and concat them and then , as there is no time for displaying page, it just shows the last page. i.e. last link's page. i just want to have this delay so that it shows a page then again uptill the last page. it's not doing that ASIM Asim
-
From your description, it sounds like the reason your code doesn't work as expected is because the loop is running on the server and is thus starting over each time. I have two that you could try, both are client-side javascript: Window.setTimeout(code, delay) - A string of script to execute after millisecods delay has expired. You could call a function that keeps track of which page to display next. setTimeout fires only once, so your function will have to reregister call setTimeout() as well. Window.setInterval(code, interval) Window.setInterval(func, interval, args...) - Similiar to setTimeout, but repeats perpetually. The second overload may be the most appropriate for your problem. HTH
-
? MEAN WHAT ? i have wrote the code below. here it is object o=null; foreach(Match m in Matchescollection) { awxWebBrowser.navigate("http://192....."+m.value().tostring(),ref o,ref o,ref o,ref o) } here Matchescollection contains all the links i.e. and on each match in the collection i want the Internet explorer to go to that link. for this i have used the m.value() concatenated with the IP of the site (here IP is permanent). this is what i want to have. now the problem is once it enters loop it just get all the values and concat them and then , as there is no time for displaying page, it just shows the last page. i.e. last link's page. i just want to have this delay so that it shows a page then again uptill the last page. it's not doing that ASIM Asim
As I said, the loop is flying through in mere milliseconds. You must put
Thread.Sleep(30000)
(30 seconds here, for example) after you navigate. For one, navigate is a non-blocking call so each iteration doesn't wait for the next to finish. Second, even if it was a blocking call, you still wouldn't have enough time to read the page. How is this hard to understand?Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
-
As I said, the loop is flying through in mere milliseconds. You must put
Thread.Sleep(30000)
(30 seconds here, for example) after you navigate. For one, navigate is a non-blocking call so each iteration doesn't wait for the next to finish. Second, even if it was a blocking call, you still wouldn't have enough time to read the page. How is this hard to understand?Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN
-
Yes, it'll work. It's supposed to work. If it didn't, there were be many things wrong with your entire system. Read the documentation for
Thread.Sleep
. The call will block for the specified time, giving the WebBrowser control enough time to load the page and you to read it, and then the method will return and the next iteration will continue. This is a simple problem.Reminiscent of my younger years...
10 LOAD "SCISSORS" 20 RUN