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.
Stop
method prevents you from careless mistakes, for example if you're evaluating theElapsed
property multiple times.Stop
would do any difference? You can't use the value anyway