C # timer regularly activates a certain time/stopwatch to calculate the module computing time

Source: Internet
Author: User

after startup, a timer is automatically activated and this is triggered when the timer time is reached. close
Public partial class form1: Form
{< br> timer my timer = new timer ();
Public form1 ()
{< br> 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 for computingProgramModule running time ..

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.