Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. foreach() problem

foreach() problem

Scheduled Pinned Locked Moved C#
helptutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asim N
    wrote on last edited by
    #1

    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

    P C H 3 Replies Last reply
    0
    • A Asim N

      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

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #2

      can we see the code...


      "When the only tool you have is a hammer, a sore thumb you will have."

      A 1 Reply Last reply
      0
      • A Asim N

        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

        C Offline
        C Offline
        CBoland
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • A Asim N

          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

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Remember that Thread.Sleep() takes time in milliseconds. This executes on the current thread, so there's no reason that Thread.Sleep(30000) shouldn't sleep for 30 seconds.

          Reminiscent of my younger years...

          10 LOAD "SCISSORS" 20 RUN

          A 1 Reply Last reply
          0
          • P Philip Fitzsimons

            can we see the code...


            "When the only tool you have is a hammer, a sore thumb you will have."

            A Offline
            A Offline
            Asim N
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • H Heath Stewart

              Remember that Thread.Sleep() takes time in milliseconds. This executes on the current thread, so there's no reason that Thread.Sleep(30000) shouldn't sleep for 30 seconds.

              Reminiscent of my younger years...

              10 LOAD "SCISSORS" 20 RUN

              A Offline
              A Offline
              Asim N
              wrote on last edited by
              #6

              ? 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

              H 1 Reply Last reply
              0
              • C CBoland

                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

                A Offline
                A Offline
                Asim N
                wrote on last edited by
                #7

                i am using c# and its a desktop application, no server side things in it. ASIM Asim

                1 Reply Last reply
                0
                • A Asim N

                  ? 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

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  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

                  A 1 Reply Last reply
                  0
                  • H Heath Stewart

                    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

                    A Offline
                    A Offline
                    Asim N
                    wrote on last edited by
                    #9

                    ok sir, so would it work in your opinion? ASIM Asim

                    H 1 Reply Last reply
                    0
                    • A Asim N

                      ok sir, so would it work in your opinion? ASIM Asim

                      H Offline
                      H Offline
                      Heath Stewart
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups