473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
Jul 21 '05 #1
10 79434
Jurgen Oerlemans <ju**************@envirolab.no_spam.nl> wrote:
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


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
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]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Jurgen Oerlemans <ju**************@envirolab.no_spam.nl> wrote:
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


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Hi Jurgen,

Threading.thread.sleep(1000)

Let the main thread sleep 1 second.

Cor

Jul 21 '05 #4
Jurgen Oerlemans <ju**************@envirolab.no_spam.nl> wrote:
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....
Well, that depends on the kind of timer you're using.

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


That suggests you haven't imported the System.Threading namespace.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
Hi John,

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

Cor
Jul 21 '05 #6
Cor Ligthert <no**********@planet.nl> wrote:
Threading.thread.sleep(1000)

Let the main thread sleep 1 second.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #7
Thank you very much helping this new newbie!
Threading.thread.sleep(1000) does the job!

Jurgen

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Cor Ligthert <no**********@planet.nl> wrote:
Threading.thread.sleep(1000)

Let the main thread sleep 1 second.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #8
Cor Ligthert <no**********@planet.nl> wrote:
When you use a timer, you need to test that in your program logic.
The threading.thread.sleep is very good for this in my opinion, because it
needs no extra program logic.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #9
>
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.

No disagrement about this,

Cor
Jul 21 '05 #10
> > Threading.thread.sleep(1000)

Let the main thread sleep 1 second.


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.


Correct
Jul 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Matik | last post by:
Hi, I have a small theoretical issue. I have one table, which is prettyu large. There is lot of evaluations running on this table, that's why, each process need to wait for another to be...
1
by: Jean-David Beyer | last post by:
I am presently running DB2 V8.1.6 on Red Hat Enterprise Linux 3 ES. Every second, the following messages appear in my /var/log/messages file: Jul 10 09:04:45 kernel: application bug:...
10
by: Jurgen Oerlemans | last post by:
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
18
by: Coder | last post by:
Howdy everybody! How do I do the following... while (myVary != true){}; Obviously I do not want to use 100% of the processor to stay in this infinite loop till myVar == true. But wait do I...
12
by: Perecli Manole | last post by:
I am having some strange thread synchronization problems that require me to better understand the intricacies of Monitor.Wait/Pulse. I have 3 threads. Thread 1 does a Monitor.Wait in a SyncLock...
14
by: stephen.durkin | last post by:
I've gathered that javascript doesn't have a handy wait() function, so I made the following function makeDelay() to make use of PHP's sleep(), which then does the waiting, and responds with...
5
by: chenthil | last post by:
In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other...
5
by: Jeremy | last post by:
Hi all, I have database actions that will potentially take several seconds to complete. My normal page uses AJAX so keeping the user informed of what is happening is not a problem. ...
4
by: Stefan Mueller | last post by:
Hallo I'm looking for a solution to display on a web page each second a new line. Unfortunately does the following solution not work with the Internet Explorer: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.