473,326 Members | 2,048 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,326 software developers and data experts.

timer oder sleep?

hello,

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

Thomas
Nov 21 '05 #1
6 1407
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..

"Thomas" <ei*@gmx.net> wrote in message
news:23********************************@4ax.com...
hello,

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

Thomas
Nov 21 '05 #2
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
Nov 21 '05 #3
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" <ei*@gmx.net> wrote in message
news:23********************************@4ax.com...
hello,

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

Thomas

Nov 21 '05 #4
"Thomas" <ei*@gmx.net> schrieb:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
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...
On Fri, 21 Jan 2005 20:38:00 +0100, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"Thomas" <ei*@gmx.net> schrieb:
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?


Nov 21 '05 #6
"Thomas" <ei*@gmx.net> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

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

Similar topics

4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: RitaG | last post by:
Hi. I Have a VB.Net Windows Application that starts up using Sub Main. It's a program that runs in the background and checks something every minute. I use a Timer to accomplish this and it's...
8
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
8
by: TheMadHatter | last post by:
Yello, Quick Q: I created a windows service that changes some data every (approx) 1sec, but currently it is using a loop on a separate thread that uses Thread.Sleep(1000). Is that bad...
4
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on...
0
by: bg_ie | last post by:
Hi all, I'm writing a .net Com object to read messages from an external bus. Also, under certain situations, I output messages to the bus in order to generate bus load, for testing purposes. An...
5
by: John A. Bailo | last post by:
From a Windows service (NET 2.0) I want to launch serveral threads in a for loop that invokes a method using: new Thread(delegate() { myMethod(248);}).Start(); Will those threads stay...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.