The Darkness Behind DateTime.Now
page 5 of 7
by Keyvan Nayyeri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 40715/ 65

QueryPerformanceCounter

While this is something that a .NET developer doesn’t need to use and care about, I have to point out that QueryPerformanceCounter is a Windows API method that is used by some built-in .NET types behind the scenes. This is considered an outdated approach in .NET development and you need to use interoperability APIs to have access to this function which provides access to a high-resolution performance counter (listing 4).

Listing 4: Using interoperability to apply QueryPerformanceCounter

[DllImport("Kernel32.dll")]
public static extern void QueryPerformanceCounter(ref long ticks);

In the next section I apply this method to compute the time taken to execute my benchmarks and the main reason is that I want to have a higher precision, so using a more fundamental operating system function can help.


View Entire Article

User Comments

Title: 你们不能明白   
Name: 巴拿马
Date: 2012-12-08 3:41:36 AM
Comment:
巴拿马






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-11-29 7:21:09 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search