473,508 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting System Ticks

Does anyone know a way to get system ticks in .Net? I found DateTime.Ticks,
but that is equal to 100 nanoseconds. The reason I'm asking is because we're
considering passing some sort of timestamp when an event fires. Do you have
any suggestions on getting this value?

Though I haven't confirmed it yet, I would think doing the following would
yield 2 different timestamps:

DateTime x = DateTime.Now;

DateTime y = DateTime.Now;

These should be different, but I'm wondering if they won't be when faster
cpus come out?

Any thoughts?
Jul 21 '05 #1
6 7019
"Michael Riggio" <mi************@unisys.nospam.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Does anyone know a way to get system ticks in .Net? I found
DateTime.Ticks, but that is equal to 100 nanoseconds. The reason
I'm asking is because we're considering passing some sort of
timestamp when an event fires. Do you have any suggestions on
getting this value?
I don't think there's a way to get a higher-resolution timer without
resorting to API calls. And, from what I've heard, there's no guarantee
that the hardware will even support one.
Though I haven't confirmed it yet, I would think doing the
following would yield 2 different timestamps: DateTime x = DateTime.Now;
DateTime y = DateTime.Now;


As I recall, DateTimes only store values at the tick level, so I don't
think that will be any different than using the Ticks property.

If it's absolutely critical that all timestamps be unique, how about the
Ticks value combined with a GUID?

Jeremy

Jul 21 '05 #2
"Michael Riggio" <mi************@unisys.nospam.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Does anyone know a way to get system ticks in .Net? I found
DateTime.Ticks, but that is equal to 100 nanoseconds. The reason
I'm asking is because we're considering passing some sort of
timestamp when an event fires. Do you have any suggestions on
getting this value?
I don't think there's a way to get a higher-resolution timer without
resorting to API calls. And, from what I've heard, there's no guarantee
that the hardware will even support one.
Though I haven't confirmed it yet, I would think doing the
following would yield 2 different timestamps: DateTime x = DateTime.Now;
DateTime y = DateTime.Now;


As I recall, DateTimes only store values at the tick level, so I don't
think that will be any different than using the Ticks property.

If it's absolutely critical that all timestamps be unique, how about the
Ticks value combined with a GUID?

Jeremy

Jul 21 '05 #3
Have you tried Environment.TickCount?

HTH;
Eric Cadwell
http://www.origincontrols.com
Jul 21 '05 #4
Have you tried Environment.TickCount?

HTH;
Eric Cadwell
http://www.origincontrols.com
Jul 21 '05 #5
Since the event sink will need to determine which events were fired first, I
don't think appending a GUID will help out in this case (though it would
surely make it unique).

Someone else recommended that I have a static long variable that is
essentially an event sequence number. The number gets incremented using
Interlocked.Increment when we fire the event. We simply handle the overflow
when the long goes back to 0.

"Jeremy Todd" <jh****@uiuc.edu> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
"Michael Riggio" <mi************@unisys.nospam.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Does anyone know a way to get system ticks in .Net? I found
DateTime.Ticks, but that is equal to 100 nanoseconds. The reason
I'm asking is because we're considering passing some sort of
timestamp when an event fires. Do you have any suggestions on
getting this value?
I don't think there's a way to get a higher-resolution timer without
resorting to API calls. And, from what I've heard, there's no guarantee
that the hardware will even support one.
Though I haven't confirmed it yet, I would think doing the
following would yield 2 different timestamps:

DateTime x = DateTime.Now;
DateTime y = DateTime.Now;


As I recall, DateTimes only store values at the tick level, so I don't
think that will be any different than using the Ticks property.

If it's absolutely critical that all timestamps be unique, how about

the Ticks value combined with a GUID?

Jeremy

Jul 21 '05 #6
Since the event sink will need to determine which events were fired first, I
don't think appending a GUID will help out in this case (though it would
surely make it unique).

Someone else recommended that I have a static long variable that is
essentially an event sequence number. The number gets incremented using
Interlocked.Increment when we fire the event. We simply handle the overflow
when the long goes back to 0.

"Jeremy Todd" <jh****@uiuc.edu> wrote in message
news:u5**************@TK2MSFTNGP10.phx.gbl...
"Michael Riggio" <mi************@unisys.nospam.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
Does anyone know a way to get system ticks in .Net? I found
DateTime.Ticks, but that is equal to 100 nanoseconds. The reason
I'm asking is because we're considering passing some sort of
timestamp when an event fires. Do you have any suggestions on
getting this value?
I don't think there's a way to get a higher-resolution timer without
resorting to API calls. And, from what I've heard, there's no guarantee
that the hardware will even support one.
Though I haven't confirmed it yet, I would think doing the
following would yield 2 different timestamps:

DateTime x = DateTime.Now;
DateTime y = DateTime.Now;


As I recall, DateTimes only store values at the tick level, so I don't
think that will be any different than using the Ticks property.

If it's absolutely critical that all timestamps be unique, how about

the Ticks value combined with a GUID?

Jeremy

Jul 21 '05 #7

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

Similar topics

11
4203
by: Vinod I | last post by:
Hi Team, I am having a string as "System.Data.SqlDbType.Int". Now I want to convert this string type to actual type to use with my Command object Parameter Creation. How I will convert this...
5
3929
by: Abdolhosein Vakilzadeh Ebrahimi | last post by:
Is there any way to construct a System.DateTime which doesn't check year, month and day to be in correct range== no validation? Thanks A.V.Ebrahimi
3
13528
by: Ivan A. | last post by:
Hi! Why I can't serialize TimeSpan structure with XmlSerializer? This is what I do: using System; using System.IO; using System.Xml; using System.Xml.Serialization;
6
427
by: Michael Riggio | last post by:
Does anyone know a way to get system ticks in .Net? I found DateTime.Ticks, but that is equal to 100 nanoseconds. The reason I'm asking is because we're considering passing some sort of timestamp...
48
4407
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
9
33038
by: AzenAlex | last post by:
Does anyone know what the C# equivalent of System.currentTimeMillis() would be?
1
6869
by: raghu1 | last post by:
How to convert a given date to its equvalent ticks.: string d="5/15/2006 12:10:44 PM"; // string 2 date ... dt=Convert.ToDateTime(d); // Date 2 ticks ... dt2ticks=dt.Ticks; string ticks =...
11
2568
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
5
4944
by: Brian | last post by:
Hello all. I have a simple application that I was using to test and understand the System.Timers.Timer and noticed that when I stop the application, on occasion, it throughs the following...
0
7129
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
7502
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
5637
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,...
1
5057
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...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
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...

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.