C # TIMER regularly activates a certain time/StopWatch to calculate the module computing time

Source: Internet
Author: User

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 ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.