473,396 Members | 1,706 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,396 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 79451
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.