我在想以下代码是否有任何我在Web服务器上运行时不知道的问题。阅读优秀系列http://reedcopsey.com/series/parallelism-in-net4/我无法找到任何与我的问题特别相关的内容,与msdn一样,所以我想我会把它带到这里。将方法引入任务以避免阻塞asp.net线程
调用示例:
public ActionResult Index() {
ViewBag.Message = "Welcome to ASP.NET MVC!";
Task.Factory.StartNew(() => {
//This is some long completing task that I don't care about
//Say logging to the database or updating certain information
System.Threading.Thread.Sleep(10000);
});
return View();
}
相关:http://stackoverflow.com/questions/3994085/are-there-any-non-obvious-dangers-in-using-threads-in-asp-net – 2011-05-02 20:16:37
感谢您的链接乔恩。我没有考虑过的一条途径,但现在对我来说显而易见的是“由于AppPool被回收”,他们可能随时死亡。绝对是我必须考虑的事情。虽然我不认为这会影响那么多,因为我不关心他们* – Buildstarted 2011-05-02 20:26:16