我试图让执行超时在ASP.NET MVC中工作。
我已经读过,执行超时仅每15s评估一次,并且只有在compilation debug="false"、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");
}
}如果执行超时是1s,而im在控制器中睡了20多个小时,那么它应该总是超过超时(最大值为16s),但是当我运行应用程序时,我总是碰到异常。
当线程超过超时时,我需要做什么才能使线程中止?
发布于 2016-10-20 14:22:41
在这种情况下睡眠不起作用。
您需要让它执行实际处理,就像for循环中的for循环执行某些操作一样。例如:
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;
}
}
}https://stackoverflow.com/questions/30316190
复制相似问题