Once started, a Timer is automatically activated and this. Close is triggered when the Timer time is reached.
Public partial class Form1: Form
{
Timer my Timer = new Timer ();
Public Form1 ()
{
InitializeComponent ();
}
Private void Form1_Load (object sender, EventArgs e)
{
My Timer. Interval = 10000; // set the time to 10 seconds
My Timer. Tick + = new EventHandler (my timer _ Tick );
My Timer. Start (); // This timer is automatically started when the form is loaded
}
// Timer timing event
Void my timer _ Tick (object sender, EventArgs e)
{
This. Close (); // when the time is up, the form Close event will be triggered.
}
}
Stopwatch can be used to calculate the running time of the program module ..
Using System. Diagnostics;
Stopwatch tm = new Stopwatch ();
Tm. Start ();
A module...
Tm. Stop ();
MessageBox. Show (tm. Elapsed. Milliseconds. ToString (), "training done ");