Monday, 23 April 2012

Silverlight Stopwatch

There’s no stopwatch in Silverlight but there is nothing to stop you rolling your own.

public class Stopwatch
{
private long _start;
private long _end;

public void Start()
{
_start = DateTime.Now.Ticks;
}

public void Stop()
{
_end = DateTime.Now.Ticks;
}

public TimeSpan ElapsedTime { get { return new TimeSpan(_end – _start); }}

public static Stopwatch StartNew()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
return stopwatch;
}
}

No comments:

Post a Comment