using System.Threading;
using System.Collections;
using System.IO;
using System.Text;
string LogPath;
Thread thread;
protected void Page_Load(object sender, EventArgs e)
{
LogPath = HttpContext.Current.Server.MapPath("log.txt");
//在应用程序启动时运行的代码
thread = new Thread(new ThreadStart(WriteLog)); //方法没有();
thread.Name = "写登录日志线程";
thread.Start();
}
//方法前面不加修饰词
void WriteLog()
{
while (true)
{
StreamWriter sw = new StreamWriter(LogPath, true, Encoding.UTF8);
sw.WriteLine(thread.Name + ":" + DateTime.Now.ToString());
sw.Close();
Thread.CurrentThread.Join(1000 * 60);//阻止1分钟
}
}