发布于 2016-05-30 22:45:07 | 132 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


在Global.asax启动一条线程就ok了,下面是启动线程定时写文件的例子.
Global.asax
C# code
 
<%@ Application Language="C#" %> 
<%@ Import Namespace="System.IO" %> 
<%@ Import Namespace="System.Threading" %> 
<script runat="server"> 
string LogPath; 
Thread thread; 
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分钟 
} 
} 
void Application_Start(object sender, EventArgs e) 
{ 
LogPath = HttpContext.Current.Server.MapPath("log.txt"); 
//在应用程序启动时运行的代码 
thread = new Thread(new ThreadStart(WriteLog)); 
thread.Name = "写登录日志线程"; 
thread.Start(); 
} 

void Application_End(object sender, EventArgs e) 
{ 
//在应用程序关闭时运行的代码 

} 

void Application_Error(object sender, EventArgs e) 
{ 
//在出现未处理的错误时运行的代码 

} 

void Session_Start(object sender, EventArgs e) 
{ 
//在新会话启动时运行的代码 

} 

void Session_End(object sender, EventArgs e) 
{ 
//在会话结束时运行的代码。 
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 
// InProc 时,才会引发 Session_End 事件。如果会话模式 
//设置为 StateServer 或 SQLServer,则不会引发该事件。 
} 
</script> 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务