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

thread ? elapsed time

Please why when I write :
while(1){
Console.writeln("date= {0:HH:mm:ss.ffff}", DateTime.Now);
System.Threadind.Thread.Sleep(40);
}
I obtain
date= 16:04:35.6250
date= 16:04:35.6718
date= 16:04:35.7187
date= 16:04:35.7656
....

Instead of :
date= 16:04:35.0040
date= 16:04:35.0080
date= 16:04:35.0120
date= 16:04:35.0160

Thanks for your informations

May 22 '06 #1
11 2282
Because Console.Writeline and while(1) themselves takes time.

May 22 '06 #2
Because Console.Writeline and while(1) themselves takes time.

May 22 '06 #3
Can I do something to abtain information every 40 ms

May 22 '06 #4

Audrey wrote:
Please why when I write :
while(1){
Console.writeln("date= {0:HH:mm:ss.ffff}", DateTime.Now);
System.Threadind.Thread.Sleep(40);
}
I obtain
date= 16:04:35.6250
date= 16:04:35.6718
date= 16:04:35.7187
date= 16:04:35.7656
...

Instead of :
date= 16:04:35.0040
date= 16:04:35.0080
date= 16:04:35.0120
date= 16:04:35.0160

Thanks for your informations


Audrey

Because the timing of the execution of a threads is unpredictable. You
have other code running besides the Sleep. The JIT compiler and
garbage collector will consume some time. Windows can preempt threads
at anytime. And that's just to name a few. There's probably a billion
other reasons that I don't even know about.

Brian

May 22 '06 #5
So I don't have solution to obtain information every 40 ms ?

May 22 '06 #6
System.Threading.Timer. Your still not going to be exact, maybe within
+-10ms.

--
William Stacey [MVP]

"Audrey" <Au*************@ifrance.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
| So I don't have solution to obtain information every 40 ms ?
|
May 22 '06 #7

Audrey wrote:
So I don't have solution to obtain information every 40 ms ?


Well, I'm not sure. You could look into multimedia timers. I have no
experience with them, but I do know they're suppose to offer better
resolution then other techniques.

May 22 '06 #8
thanks ok I go and try it

May 22 '06 #9
thanks ok I go and try it

May 22 '06 #10
multimedia timers refer to System.Threading.Timer ?

May 22 '06 #11

"Audrey" <Au*************@ifrance.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
| multimedia timers refer to System.Threading.Timer ?
|

No, MM timers are Winmm.dll exported functions. Anyway, you don't need to
experiment with these, it's simply no possible to put a thread asleep for a
precise amount of time in Windows. The closest you can get is the
"sleep-time" +/- RTC clock interval(10 msec or more).

Willy.
May 22 '06 #12

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

Similar topics

1
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
11
by: Philip Wagenaar | last post by:
Hello, I am using a timer object in my Windows Forms Application. Does the code in ..elapsed event run in a diffrent thread? If the interval is set to 10 milliseconds and the time to execute the...
11
by: Michael Moreno | last post by:
Hello, I have a C# server which has 4 worker threads running all the time. When I let the server runs for several hours, for some reasons the CPU usage of the application will shoot to 100% and...
12
by: newscorrespondent | last post by:
There are many examples of how to get the elapsed time for a method but I can't find any example of how to measure the amount of CPU consumed by my thread in a method. Elapsed time in a...
3
by: Jack | last post by:
I have an application (COM Add-in) that in the initialization code it displays a splash screen. I want the splash screen to close after n seconds , so I add a timer to the splash screen and...
10
by: Bishman | last post by:
Hi, I have a form application that needs to query a DB at a set timed interval and then refresh the form with values received from the DB. Simple enough. My design releated questions are .......
5
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the...
12
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
5
by: Kate77 | last post by:
Hello, Im trying to do something very simple but having problems.. What I want to accomplish sounds simple but I cant find anywhere on the web answer of how to do that so it will work. I want...
9
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.