WEBアプリケーションに基づいています。 NET MVC 3次のように、コードをC#の非同期動作値の誤差を確立するために:C#非同期処理オペレーションエラー
public ActionResult Contact()
{
// Create an asynchronous processing operations
Task task = new Task (() => {
string [] testTexts = new string [10] {"a", "b", "c", "d", "e", "f", "g", "h" , "i", "j"};
foreach (string text in testTexts)
{
// The following line does not have a problem
System.IO.File.AppendAllText (Server.MapPath ("/ test.txt"), text);
// The following line to be a problem, find a solution. Because some other program of practical application in my project set to use System.Web.HttpContext.Current
// System.IO.File.AppendAllText (System.Web.HttpContext.Current.Server.MapPath ("/ test.txt"), text);
// Thread to hang five seconds to simulate asynchronous time difference
System.Threading.Thread.Sleep (5000);
}
});
// Asynchronous processing
task.Start();
return View();
}
System.Web.HttpContext.Currentこの行を使用している理由は何ですか –