ASP.NET(C#)タイミングでコードを実行

1628 ワード

Global.asax
C# code
 
  



<br>string LogPath; <br>Thread thread; <br>void WriteLog() <br>{ <br>while (true) <br>{ <br>StreamWriter sw = new StreamWriter(LogPath, true, Encoding.UTF8); <br>sw.WriteLine(thread.Name + ":" + DateTime.Now.ToString()); <br>sw.Close(); <br>Thread.CurrentThread.Join(1000 * 60);// 1 <br>} <br>} <br>void Application_Start(object sender, EventArgs e) <br>{ <br>LogPath = HttpContext.Current.Server.MapPath("log.txt"); <br>// <br>thread = new Thread(new ThreadStart(WriteLog)); <br>thread.Name = " "; <br>thread.Start(); <br>} <br> <br>void Application_End(object sender, EventArgs e) <br>{ <br>// <br> <br>} <br> <br>void Application_Error(object sender, EventArgs e) <br>{ <br>// <br> <br>} <br> <br>void Session_Start(object sender, EventArgs e) <br>{ <br>// <br> <br>} <br> <br>void Session_End(object sender, EventArgs e) <br>{ <br>// 。 <br>// : Web.config sessionstate <br>// InProc , Session_End 。 <br>// StateServer SQLServer, 。 <br>} <br>