我在想以下代碼是否有任何我在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