Let's imagine we have simple measurements using Stopwatch
public void DoWork()
{
var timer = Stopwatch.StartNew();
// some hard work
Logger.Log("Time elapsed: {0}", timer.Elapsed);
timer.Stop(); // Do I need to call this?
}
According to MSDN:
In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.
I'm not sure if I should call this method when I'm no longer interested with timer instance. Should I "clear up" using Stop
method?
EDIT
Keep in mind that Logger.Log(..) costs nothing because timer.Elapsed
is read before the logger logs.