ASP.NET Execution

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

I read that the execution timeout is only evaluated every 15 seconds 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 cannot get it to ever trigger a timeout.

I have a main MVC application (outside the template) and 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 16s), but when I run the application I always get caught in my exception.

What do I need to do to interrupt the thread when it times out?

+3


source to share


1 answer


Sleep does not work in this case.

You will need to do actual processing, like a for loop in a for loop that does 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;
        }
    }
}

      

0


source







All Articles