Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

my code:

using (new SPMonitoredScope("Sleepy Time", 1000)) {
    System.Threading.Thread.Sleep(5000);
}

when I enable the Developer Dashboard, I am expecting a red border around it because the code running in the monitored scope is running longer than 1000 milliseconds.

But it doesn't happen. I do get a bullet point in the Developer Dashboard such as

  • Sleepy Time (5008.26 ms)

but no indication that the counter was triggered. Can anyone explain why?

share|improve this question

2 Answers 2

DD only show you the standard events called by SharePoint. Eg OnPreRender, CreateChildControls etc.

If you want to add monitors to a web part, you would need to create a method like this

private void SleepyTime()
{
    using (SPMonitoredScope scope = new SPMonitoredScope("SleepyTime"))
    {                
        System.Threading.Thread.Sleep(5000);
    }
}

and it would show up in DD from the overridden event from which the method was called CreateChildControls (50xx ms) - SleepyTime (5000 ms)

Note that the code above wont run in a sandboxed solution!

You can also create a custom monitored scope using the ISPScopedPerformanceMonitor interface. This is used in conjunction with an overridden constructor

int maxExecutionTime = 1000; // The maximum duration of the monitoring operation, in milliseconds
using (SPMonitoredScope scope = new SPMonitoredScope("SleepyTime", maxExecutionTime, new MyCustomMonitor()))
{
    // MyCustomMonitor implements ISPScopedPerformanceMonitor interface
    // If monitoring the scope exceeds the time represented by the maximumExecutionTime value, you can use the maximumExecutionTime value to increase the logging level.
}
share|improve this answer

The red border is only triggered by SharePoint defined monitors at the root scope. A yellow border should indicate that the request took more than one second.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.