Application of program timer stopwatch class

Source: Internet
Author: User

Stopwatch provides several methods to control the stopwatch object. The start method starts a timing operation, and the Stop method stops timing. If the start method is used for the second time, the timing continues, and the final result is the accumulation of the two times. To avoid this, use the reset method to zero the object before the second timer. No parameters are required for these three methods.

Namespace: system. Diagnostics

Constructor: stopwatch Sw = new stopwatch ();

Method:

Start starts or continues to measure the running time at a certain interval.

Stop stops measuring the running time at a certain interval.

Reset reset timer.

Elapsed obtains the total running time measured by the current instance.

Usage:

Using system. diagnostics;

 

Stopwatch Sw = new stopwatch ();

Sw. Start ();

// The program code for timing is here

Sw. Stop ();

Double time = Sw. elapsed. totalmilliseconds;

MessageBox. Show ("program time:" + time );

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.