Monday 2 November 2015

ASP.NET Tips #44 - Take advantage of spans

Spans – regions of code to explicitly demarcate on a timeline graph – are a great feature in Concurrency Visualizer. There are two big things to watch out for.

Firstly, when instrumenting spans, the documentation suggests you use:

var span = Markers.EnterSpan(description);
// do stuff here
span.Leave();

That pattern is more error prone than it needs to be – you must manually ensure and remember to "close" your span through all code pathways.

Secondly, you can enhance their disposable nature further with the using statement:

using (Markers.EnterSpan(description))
{
   // do stuff here
}

No comments :

Post a Comment