Stopwatch Sınıfı - CSharp


Temel kronometre işlemlerinin yapılmasını sağlayan csharp sınıfı alternatifidir.

Kod


public class StopwatchVs
{
    //--------------------------------------------------
    // Genel Metotlar
    //--------------------------------------------------
    #region Baslat
    public static void Baslat(Stopwatch stopwatch)
    {
        stopwatch.Start();
    }
    #endregion

    #region Durdur
    public static void Durdur(Stopwatch stopwatch)
    {
        stopwatch.Stop();
    }
    #endregion

    #region Sifirla
    public static void Sifirla(Stopwatch stopwatch)
    {
        stopwatch.Reset();
    }
    #endregion

    #region YenidenBaslat
    public static void YenidenBaslat(Stopwatch stopwatch)
    {
        stopwatch.Restart();
    }
    #endregion

    #region GecenZaman
    public static string GecenZaman(Stopwatch stopwatch)
    {
        TimeSpan ts = new TimeSpan();
        ts = stopwatch.Elapsed;

        return String.Format("{0:00}:{1:00}:{2:00}",
            ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 1000);
    }
    #endregion

    #region GecenZamaniYazdirKronometreyiYenidenBaslat
    public static string GecenZamaniYazdirKronometreyiYenidenBaslat(Stopwatch stopwatch)
    {
        TimeSpan ts = new TimeSpan();
        ts = stopwatch.Elapsed;
        stopwatch.Restart();

        return String.Format("{0:00}:{1:00}:{2:00}",
            ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 1000);
    }
    #endregion
}

Etiketler
csharp