vb: how to wait for a second?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jurgen Oerlemans

    vb: how to wait for a second?

    I have a code where I perform several actions on files.
    Between these actions I want to wait for 1 second. Or 2 seconds.
    How can I easily do this without using a timer? Jurgen


  • Jon Skeet [C# MVP]

    #2
    Re: vb: how to wait for a second?

    Jurgen Oerlemans <jurgen.oerlema ns@envirolab.no _spam.nl> wrote:[color=blue]
    > I have a code where I perform several actions on files.
    > Between these actions I want to wait for 1 second. Or 2 seconds.
    > How can I easily do this without using a timer? Jurgen[/color]

    Well, Thread.Sleep will make the current thread pause for a second. You
    don't want to do that on a UI thread though...

    Out of interest, why do you want to avoid using a timer?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Jurgen Oerlemans

      #3
      Re: vb: how to wait for a second?

      well, to be quite frankly I don't know how to use a timer for a simple
      wait-statement.
      I use one to perform an action every 5 minutes, but don't know how to use
      one to pause the program for a second and then proceed....

      Also, using thread.sleep gives me also all kinds of errors like
      Name 'Thread' is not declared.

      Jurgen




      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1b4a2c 729e1a6c0898add 9@msnews.micros oft.com...[color=blue]
      > Jurgen Oerlemans <jurgen.oerlema ns@envirolab.no _spam.nl> wrote:[color=green]
      > > I have a code where I perform several actions on files.
      > > Between these actions I want to wait for 1 second. Or 2 seconds.
      > > How can I easily do this without using a timer? Jurgen[/color]
      >
      > Well, Thread.Sleep will make the current thread pause for a second. You
      > don't want to do that on a UI thread though...
      >
      > Out of interest, why do you want to avoid using a timer?
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Cor Ligthert

        #4
        Re: how to wait for a second?

        Hi Jurgen,

        Threading.threa d.sleep(1000)

        Let the main thread sleep 1 second.

        Cor



        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: vb: how to wait for a second?

          Jurgen Oerlemans <jurgen.oerlema ns@envirolab.no _spam.nl> wrote:[color=blue]
          > well, to be quite frankly I don't know how to use a timer for a simple
          > wait-statement.
          > I use one to perform an action every 5 minutes, but don't know how to use
          > one to pause the program for a second and then proceed....[/color]

          Well, that depends on the kind of timer you're using.

          See http://www.pobox.com/~skeet/csharp/m...ng.html#timers
          [color=blue]
          > Also, using thread.sleep gives me also all kinds of errors like
          > Name 'Thread' is not declared.[/color]

          That suggests you haven't imported the System.Threadin g namespace.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Cor Ligthert

            #6
            Re: vb: how to wait for a second?

            Hi John,

            When you use a timer, you need to test that in your program logic.
            The threading.threa d.sleep is very good for this in my opinion, because it
            needs no extra program logic.

            Cor


            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: how to wait for a second?

              Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue]
              > Threading.threa d.sleep(1000)
              >
              > Let the main thread sleep 1 second.[/color]

              Very slight clarification: it makes the *current* thread sleep for one
              second, whether or not this is the "main" thread. You can't make other
              threads sleep.

              --
              Jon Skeet - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Jurgen Oerlemans

                #8
                Re: how to wait for a second?

                Thank you very much helping this new newbie!
                Threading.threa d.sleep(1000) does the job!

                Jurgen

                "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
                news:MPG.1b4a36 29ac585a8d98add d@msnews.micros oft.com...[color=blue]
                > Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=green]
                > > Threading.threa d.sleep(1000)
                > >
                > > Let the main thread sleep 1 second.[/color]
                >
                > Very slight clarification: it makes the *current* thread sleep for one
                > second, whether or not this is the "main" thread. You can't make other
                > threads sleep.
                >
                > --
                > Jon Skeet - <skeet@pobox.co m>
                > http://www.pobox.com/~skeet
                > If replying to the group, please do not mail me too[/color]


                Comment

                • Jon Skeet [C# MVP]

                  #9
                  Re: vb: how to wait for a second?

                  Cor Ligthert <notfirstname@p lanet.nl> wrote:[color=blue]
                  > When you use a timer, you need to test that in your program logic.
                  > The threading.threa d.sleep is very good for this in my opinion, because it
                  > needs no extra program logic.[/color]

                  It entirely depends on what you're trying to do. If you want something
                  to happen in the UI thread in a second, then blocking the UI thread for
                  a second is a nightmare. If you're just waiting to retry something on a
                  worker thread, it's absolutely fine.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                  If replying to the group, please do not mail me too

                  Comment

                  • Cor Ligthert

                    #10
                    Re: vb: how to wait for a second?

                    >[color=blue]
                    > It entirely depends on what you're trying to do. If you want something
                    > to happen in the UI thread in a second, then blocking the UI thread for
                    > a second is a nightmare. If you're just waiting to retry something on a
                    > worker thread, it's absolutely fine.
                    >[/color]
                    No disagrement about this,

                    Cor


                    Comment

                    • Cor Ligthert

                      #11
                      Re: how to wait for a second?

                      > > Threading.threa d.sleep(1000)[color=blue][color=green]
                      > >
                      > > Let the main thread sleep 1 second.[/color]
                      >
                      > Very slight clarification: it makes the *current* thread sleep for one
                      > second, whether or not this is the "main" thread. You can't make other
                      > threads sleep.[/color]

                      Correct


                      Comment

                      Working...