DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

21
kicks
published 2 years, 1 month ago, submitted by mikeon 2 years, 1 month ago

vaultofthoughts.net — How to accurately measure how much time has passed while performing some operation? Use the Stopwatch class. Here is how.

tags: , , , , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
Easy, handy, I like it. thanks
posted by fatdaveh 2 years, 1 month ago
This is exactly what I was looking for, even before I started looking for it ;) Great kick, thanks!
posted by superghost superghost 2 years, 1 month ago
Hey Thanks All,

I tried Stopwatch .NET 2.0 but its not found, or i think i am missing some reference.
So i used the following program, and it worked fine.

using System;
using System.Runtime.InteropServices;
namespace TestSqlTimeOutException_Soundar
{
public sealed class StopWatch
{
[DllImport("kernel32.dll")]
extern static int QueryPerformanceCounter(ref long x);

[DllImport("kernel32.dll")]
extern static int QueryPerformanceFrequency(ref long x);


public StopWatch()
{
Frequency = GetFrequency();
Reset();
}

public void Reset()
{
StartTime = GetValue();
}

public long Peek()
{
return (long)(((GetValue() - StartTime)
/ (double)Frequency) * 10000);
}

private long GetValue()
{
long ret = 0;
if (QueryPerformanceCounter(ref ret) == 0)
throw new NotSupportedException(
"Error while querying "
+ "the high-resolution performance counter.");
return ret;
}

private long GetFrequency()
{
long ret = 0;
if (QueryPerformanceFrequency(ref ret) == 0)
throw new NotSupportedException(
"Error while querying "
+ "the performance counter frequency.");
return ret;
}

private long StartTime
{
get
{
return m_StartTime;
}
set
{
m_StartTime = value;
}
}

private long Frequency
{
get
{
return m_Frequency;
}
set
{
m_Frequency = value;
}
}



#region -- Private Variables --

/// <summary>
/// Holds the value of the StartTime property.
/// </summary>
private long m_StartTime;

/// <summary>
/// Holds the value of the Frequency property.
/// </summary>
private long m_Frequency;

#endregion

}
}
posted by sdhakshina 11 months, 12 days ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge