473,586 Members | 2,702 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 7047
"Michael Riggio" <mi************ @unisys.nospam. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP09.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.Tic kCount?

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

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.Inc rement when we fire the event. We simply handle the overflow
when the long goes back to 0.

"Jeremy Todd" <jh****@uiuc.ed u> wrote in message
news:u5******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Riggio" <mi************ @unisys.nospam. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.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.Inc rement when we fire the event. We simply handle the overflow
when the long goes back to 0.

"Jeremy Todd" <jh****@uiuc.ed u> wrote in message
news:u5******** ******@TK2MSFTN GP10.phx.gbl...
"Michael Riggio" <mi************ @unisys.nospam. com> wrote in message
news:OY******** ******@TK2MSFTN GP09.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
4219
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 string to the type object ?. Thanks in advance
5
3937
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
13542
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 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...
48
4439
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 lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should...
9
33057
by: AzenAlex | last post by:
Does anyone know what the C# equivalent of System.currentTimeMillis() would be?
1
6876
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 = Convert.ToString(dt2ticks);
11
2587
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 library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
5
4960
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 exception. An exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll but was not handled in user code Additional...
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
5710
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...
0
3836
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
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
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
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...

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.