最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET(C#) 定時(shí)執(zhí)行一段代碼

 更新時(shí)間:2009年11月26日 19:05:09   作者:  
在Global.asax啟動(dòng)一條線程就ok了,下面是啟動(dòng)線程定時(shí)寫文件的例子.
Global.asax
C# code
復(fù)制代碼 代碼如下:

<%@ 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");
//在應(yīng)用程序啟動(dòng)時(shí)運(yùn)行的代碼
thread = new Thread(new ThreadStart(WriteLog));
thread.Name = "寫登錄日志線程";
thread.Start();
}

void Application_End(object sender, EventArgs e)
{
//在應(yīng)用程序關(guān)閉時(shí)運(yùn)行的代碼

}

void Application_Error(object sender, EventArgs e)
{
//在出現(xiàn)未處理的錯(cuò)誤時(shí)運(yùn)行的代碼

}

void Session_Start(object sender, EventArgs e)
{
//在新會(huì)話啟動(dòng)時(shí)運(yùn)行的代碼

}

void Session_End(object sender, EventArgs e)
{
//在會(huì)話結(jié)束時(shí)運(yùn)行的代碼。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式設(shè)置為
// InProc 時(shí),才會(huì)引發(fā) Session_End 事件。如果會(huì)話模式
//設(shè)置為 StateServer 或 SQLServer,則不會(huì)引發(fā)該事件。
}
</script>

相關(guān)文章

最新評(píng)論

贵港市| 百色市| 上蔡县| 苏尼特左旗| 卢龙县| 崇明县| 安丘市| 类乌齐县| 宁南县| 志丹县| 永济市| 黎城县| 梨树县| 萝北县| 盐城市| 扎鲁特旗| 龙游县| 龙海市| 锡林郭勒盟| 兴隆县| 富川| 肥乡县| 宕昌县| 长宁县| 怀远县| 大同县| 新丰县| 闻喜县| 石门县| 商都县| 兴业县| 太和县| 玉溪市| 湘乡市| 白河县| 即墨市| 陆河县| 南宫市| 桐庐县| 璧山县| 原平市|