locked
Creating a delay in a loop without Thread.Sleep() RRS feed

  • Question

  • User56046257 posted

    i have a web browser control, that refreshes pages on a loop after calling a few subs, i need to create a delay in the loop so that the page has a chance to refresh and redisplay before it loops again. i tried the code below, but it seemed to freeze the entire form, elements including, so the web browser didnt refresh before the loop, so how could i create a non form-freezing delay for a loop?

    For count = 1 To 20
    WebBrowser1.Navigate("URL")
    simcheckcheck()
    vitcheckcheck()
    System.Threading.Thread.Sleep(7000)



    Sunday, April 22, 2012 6:53 PM

Answers

  • User197322208 posted
    Thread.Sleep works in the current thread. If you put 
    Navigate 
    in another thread, it does not sleep.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 23, 2012 1:03 AM

All replies

  • User197322208 posted

    Put this

    WebBrowser1.Navigate("URL")

    on other thread / task.

    Sunday, April 22, 2012 7:18 PM
  • User56046257 posted

    sorry if this sounds like a silly question, but how does this help? surely if the object is frozen then being activated in a different sub will have little difference.

    Sunday, April 22, 2012 7:43 PM
  • User197322208 posted
    Thread.Sleep works in the current thread. If you put 
    Navigate 
    in another thread, it does not sleep.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 23, 2012 1:03 AM
  • User839249405 posted

    Hi,

    using System.Threading;
    
    Thread thread2 = new Thread(new ThreadStart(WorkThreadFunction));
    thread2.Start();
    

    [C#]
    public void WorkThreadFunction()
    {
      try
      {
        For count = 1 To 20 
    WebBrowser1.Navigate("URL") } catch (Exception ex) { // log errors } }


     

    Wednesday, April 25, 2012 7:27 AM