473,801 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

thread ? elapsed time

Please why when I write :
while(1){
Console.writeln ("date= {0:HH:mm:ss.fff f}", DateTime.Now);
System.Threadin d.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 2315
Because Console.Writeli ne and while(1) themselves takes time.

May 22 '06 #2
Because Console.Writeli ne 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.fff f}", DateTime.Now);
System.Threadin d.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.Threadin g.Timer. Your still not going to be exact, maybe within
+-10ms.

--
William Stacey [MVP]

"Audrey" <Au************ *@ifrance.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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

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

Similar topics

1
12346
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 minutes 5 seconds". Any ideas? Thanks very much! function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time;
11
7566
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 code in the .elapsed event takes 1 secocond to complete, what happens? 1) Timer starts. 10 milliseconds later the code is executed and timer stops. When code is done, 1 seconds later, the timer continues. 10 milliseconds later the code is...
11
6062
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 remain there. I would like to find out which thread(s) is/are the source of the problem. Would you have any idea on how to tackle the problem please?
12
4142
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 multithreaded application particularly on a single processor CPU is not very useful. Is there a way to measure this? Thanks. Tom
3
3979
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 attempt to close it from the Elapsed event. And I get the Cross-thread error. Conceptually I think I know why this error occurs, I am just not sure how to solve it, since the form was shown from a section of code that is no longer running. Any...
10
1275
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 .... Should I create a worker thread that encapsulates a timer, (which I believe will also create a seperate thread when the timer fires) , or should I create a timer that creates a new thread when it fires ? Or neither ?
5
12251
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 event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
12
16381
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()' function call for the purpose and regardless of how many time I invoke the function within my program, I get the same output!!! For better clarity consider the code snippet below. ... start_time = time(NULL);
5
18917
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 to run a thread , for example map the files on the hard drive. now what I want to do is run a timer that will check the thread state so when it is finish the timer will run a second thread that will map the files on the hard drive again but with...
9
3319
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 clear, as is creating a second: nowTime = new Date(); and getting a difference between the two. My quesiton is what if you have many, maybe thousands of intervals you wish to measure? Should I do: nowTime = new Date(); with every pass of a...
0
9558
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10298
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10278
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9105
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7594
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4265
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2963
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.