timer oder sleep?

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

hello,

what is the better solution if it is possible to choose?
a timer or sleep? which one is better for min resources?

Thomas
 
I believe Sleep blocks, so nothing will execute during the sleep duration.
A timer is asynchronous, so other code can execute between timer events.

Neither is necessarily better or worse, they are used for different
situations. Resources for either are practically non- existent..

hello,

what is the better solution if it is possible to choose?
a timer or sleep? which one is better for min resources?

Thomas
 
Thomas,

When it is one time sleep than obvious sleep, however probably you ask this
is na repeated sleep and than it is of course a timer.

Just my thought,

Cor
 
AFAIK, they really have different purposes. A timer will fire an event
every X milliseconds. Sleep will pause execution of a thread for X
milliseconds. What is it you are trying to do?

Chris
 
Thomas said:
what is the better solution if it is possible to choose?
a timer or sleep? which one is better for min resources?

This depends on what you want to archieve. Can you describe the scenario in
more detail?
 
i know that these two ways are different, but i only wonna know if it
is better to use sleep or timer if there is a possibility to choose...

i.e. if the timer is taking much resources than i try to use the
sleep... thats what i thinked about...

but i think it is like ... sleep is using more resources

i have an app with a few timers...the app is always running ... one
timer to check if there is an update available... one timer to check a
freespace... one to check for a service...and so on... but these
things should be checked at different intervalls... so i thought about
using an alternative... but if a timer is ok than i will use timers...
 
Thomas said:
i know that these two ways are different, but i only wonna know if it
is better to use sleep or timer if there is a possibility to choose...

i.e. if the timer is taking much resources than i try to use the
sleep... thats what i thinked about...

but i think it is like ... sleep is using more resources

This depends on how 'Sleep' is implemented. If it's implemented as a busy
waiting loop, then it will take a lot of CPU time. If you are using
'Thread.Sleep', this is not the case, but the thread is really blocked. If
you are calling 'Thread.Sleep' in the application's main UI thread, the user
won't be able to use the user interface while the thread is blocked.
i have an app with a few timers...the app is always running ... one
timer to check if there is an update available... one timer to check a
freespace... one to check for a service...and so on... but these
things should be checked at different intervalls... so i thought about
using an alternative... but if a timer is ok than i will use timers...

I would use a timer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top