Sun May 13, 2007 11:05 pm
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main()
{
// Creating an instance of Stopwatch
Stopwatch myWatch = new Stopwatch();
// Start counting
myWatch.Start();
// Any thing that take time
for (int i = 0; i < 200; i++)
{
// Sleep
Thread.Sleep(1);
}
// Stop the watch
myWatch.Stop();
// Write result
Console.WriteLine("Your program took :time elapsed: {0}",
myWatch.Elapsed);
}
}
using System;
using System.Diagnostics;
using System.Threading;
class Program
{
static void Main()
{
Stopwatch myWatch = Stopwatch.StartNew();
// Sleep for five seconds
Thread.Sleep(5000);
// Restart the time counter
stop.Restart();
// Sleep again
Thread.Sleep(2000);
// The time difference should be 2 seconds only.
Console.WriteLine(stop.ElapsedMilliseconds);
}
}
Fri Mar 27, 2009 12:30 am
|
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.