使用 asp.net mvc 4,
我用这样的静态方法创建了一个类
public class StaticClass
{
public static int val { get; set; }
public static string ReturnValueBasedOnInput(int n)
{
string res;
switch (n)
{
case 101:
Thread.Sleep(30000);
res = "Long lasting response: 101" + val;
break;
default:
res = n.ToString() + " was provided..." + val;
break;
}
return res;
}
}
它是从我的控制器调用的:
public ActionResult Index(int id = 1)
{
ViewBag.returnValue = StaticClass.ReturnValueBasedOnInput(id);
return View(id);
}
我希望当我调用参数值为 101 的方法时,应用程序应该被阻止 30 秒,但它仍然响应。我认为由于这是一个静态方法,因此所有传入的方法调用都应该被阻止 30 秒。有人可以解释这里发生了什么吗?