C#計算プログラム実行時間


 (.net1.1  .net2.0 ) .net2.0 Stopwatch , 
using System.Diagnostics;

private Stopwatch stw = new Stopwatch();

private void Form1_Load(object sender, EventArgs e)
{
stw.Start();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show(" ?", " ", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
stw.Stop();
MessageBox.Show(" :" + stw.Elapsed.Seconds.ToString() + " ");
e.Cancel = false;
}
else
{
e.Cancel = true;
}
}

.net1.1 ,
using System;
namespace StopWatchTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
StopWatch sw = new StopWatch();
sw.start();
for (long i = 0 ; i < 100000000 ; i++)
{

}
Console.WriteLine(sw.elapsed());

Console.Read();
}
}

class StopWatch
{
private int mintStart;

public void start()
{
mintStart = Environment.TickCount;
}

public long elapsed()
{
return Environment.TickCount - mintStart;
}
}
}