private void btnStartWorking_Click(object sender, EventArgs e) { if (cbTwoSeconds.Checked) _timer = new Caliper("Tests.StartStop", new TimeSpan(0,0,2)); else _timer = new Caliper("Tests.StartStop"); Trace.WriteLine("Start Working..."); _timer.Start(); }
/// <summary> /// The Start/Stop methods on a Caliper are also handy for tight loops /// in which we want to be extra performant and would like to avoid the /// extra level of indentation a using block would impose. /// </summary> private void btnWorkRepeatedly_Click(object sender, EventArgs e) { var timer = new Caliper("Tests.Loop"); var rand = new Random(); Trace.WriteLine("Begin Loop..."); Trace.Indent(); for (var i = 1; i <= nudWorkRepeatedly.Value; i++) { Trace.WriteLine("Iteration " + i); var ms = rand.Next(0, 100); timer.Start(); Thread.Sleep(ms); timer.Stop(); } Trace.Unindent(); Trace.WriteLine("End Loop"); }