473,326 Members | 2,173 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.

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 6996
"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
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
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
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
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
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
by: AzenAlex | last post by:
Does anyone know what the C# equivalent of System.currentTimeMillis() would be?
1
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
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
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
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: 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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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.