4

I'm trying to get execution timeouts working in ASP.NET MVC.

I have read that the execution timeout is only evaluated every 15s and only when compilation debug="false", http://blogs.msdn.com/b/pedram/archive/2007/10/02/how-the-execution-timeout-is-managed-in-asp-net.aspx.

However I cant seem to get it to ever trigger a timeout.

I have a basic MVC application (off the template) and have made the following changes:

web.config:

<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" executionTimeout="1" />

HomeController:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        Thread.Sleep(20000);
        throw new Exception("Shouldnt get here as its longer than the execution timeout +15s");
    }
}

If the execution timeout is 1s and im sleeping for 20s in the controller it should always exceed the timeout (max of 16s), but when i run the application I always hit my exception.

What do I need to do to get the thread to abort when it exceeds the timeout?

undefined
  • 33,537
  • 22
  • 129
  • 198

1 Answers1

0

Sleep does not work in this case.

You will need to make it do actual processing, like a for loop in a for loop doing something. For example:

var t = 1;
for (int i = 0; i < 99999999; i++)
{
    for (int i2 = 0; i2 < 99999999; i2++)
    {
        for (int i3 = 0; i3 < 99999999; i2++)
        {
            t = i + i2 - i3;
        }
    }
}
Andrew Marais
  • 925
  • 9
  • 13