[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern uint GetTickCount();
// GET: Home
public ActionResult Index()
{
//System.Threading.Sleep(3000); // 在MVC中报错, 没有引用 mscorlib(在 mscorlib.dll 中), 引用的时候 未能添加mscorlib的引用,此组件由生成系统自动引用.
Thread.Sleep(1000); 这是正确的
MySleep(30000);
return View();
}
/// <summary>
/// 程序等待延迟执行
/// </summary>
/// <param name="ms"></param>
static void MySleep(uint ms)
{
uint start = GetTickCount(); //获取系统运行了多长时间 , 返回值,毫秒
while (GetTickCount() - start < ms) //当前运行时间 和之前运行时间做比较
{
//Application.DoEvents();
}
}