我正在尝试在ASP.NET MVC中实现执行超时。
我已经了解到,执行超时只有在compilation debug="false"
的情况下每15秒才进行一次评估,详情请参见http://blogs.msdn.com/b/pedram/archive/2007/10/02/how-the-execution-timeout-is-managed-in-asp-net.aspx。
然而,我似乎无法触发超时。
我有一个基本的MVC应用程序(来自模板),并进行了以下更改:
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");
}
}
如果执行超时时间为1秒,而控制器中的睡眠时间为20秒,则总是超过超时时间(最大16秒),但当我运行应用程序时,总是会出现异常。
为了在超时时终止线程,我需要做什么?