Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Método Stopwatch.Start ()

 

Inicia, ou continua, medindo o tempo decorrido para um intervalo.

Namespace:   System.Diagnostics
Assembly:  System (em System.dll)

public void Start()

In a typical T:System.Diagnostics.Stopwatch scenario, you call the M:System.Diagnostics.Stopwatch.Start method, then eventually call the M:System.Diagnostics.Stopwatch.Stop method, and then you check elapsed time using the P:System.Diagnostics.Stopwatch.Elapsed property.

Once started, a T:System.Diagnostics.Stopwatch timer measures the current interval, in elapsed timer ticks, until the instance is stopped or reset. Starting a T:System.Diagnostics.Stopwatch that is already running does not change the timer state or reset the elapsed time properties.

When a T:System.Diagnostics.Stopwatch instance measures more than one interval, the M:System.Diagnostics.Stopwatch.Start method resumes measuring time from the current elapsed time value. A T:System.Diagnostics.Stopwatch instance calculates and retains the cumulative elapsed time across multiple time intervals, until the instance is reset. Use the M:System.Diagnostics.Stopwatch.Reset method before calling M:System.Diagnostics.Stopwatch.Start to clear the cumulative elapsed time in a T:System.Diagnostics.Stopwatch instance. Use the M:System.Diagnostics.Stopwatch.Restart method to M:System.Diagnostics.Stopwatch.Reset and M:System.Diagnostics.Stopwatch.Start the T:System.Diagnostics.Stopwatch with a single command.

The following example demonstrates how to use the M:System.Diagnostics.Stopwatch.Start method to start a timer that measures the execution time of an application.

using System;
using System.Diagnostics;
using System.Threading;
class Program
{
    static void Main(string[] args)
    {
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();
        Thread.Sleep(10000);
        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        TimeSpan ts = stopWatch.Elapsed;

        // Format and display the TimeSpan value.
        string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);
        Console.WriteLine("RunTime " + elapsedTime);
    }
}

Plataforma Universal do Windows
Disponível desde 8
.NET Framework
Disponível desde 2.0
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Windows Phone Silverlight
Disponível desde 7.0
Windows Phone
Disponível desde 8.1
Retornar ao início
Mostrar: