473,395 Members | 1,730 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,395 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 7004
"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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,...

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.