免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

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

在Global.asax啟動(dòng)一條線程就ok了,下面是啟動(dòng)線程定時(shí)寫文件的例子

Global.asax

  1. <%@ Application Language="C#" %> 
  2. <%@ Import Namespace="System.IO" %> 
  3. <%@ Import Namespace="System.Threading" %> 
  4. <script runat="server"
  5.     string LogPath; 
  6.     Thread thread; 
  7.     void WriteLog() 
  8.     { 
  9.         while (true
  10.         { 
  11.             StreamWriter sw = new StreamWriter(LogPath, true, Encoding.UTF8); 
  12.             sw.WriteLine(thread.Name + ":" + DateTime.Now.ToString()); 
  13.             sw.Close(); 
  14.             Thread.CurrentThread.Join(1000 * 60);//阻止1分鐘 
  15.         } 
  16.     } 
  17.     void Application_Start(object sender, EventArgs e) 
  18.     { 
  19.         LogPath = HttpContext.Current.Server.MapPath("log.txt"); 
  20.         //在應(yīng)用程序啟動(dòng)時(shí)運(yùn)行的代碼 
  21.          thread = new Thread(new ThreadStart(WriteLog)); 
  22.         thread.Name = "寫登錄日志線程"
  23.         thread.Start(); 
  24.     } 
  25.     
  26.     void Application_End(object sender, EventArgs e) 
  27.     { 
  28.         //在應(yīng)用程序關(guān)閉時(shí)運(yùn)行的代碼 
  29.  
  30.     } 
  31.         
  32.     void Application_Error(object sender, EventArgs e) 
  33.     { 
  34.         //在出現(xiàn)未處理的錯(cuò)誤時(shí)運(yùn)行的代碼 
  35.  
  36.     } 
  37.  
  38.     void Session_Start(object sender, EventArgs e) 
  39.     { 
  40.         //在新會(huì)話啟動(dòng)時(shí)運(yùn)行的代碼 
  41.  
  42.     } 
  43.  
  44.     void Session_End(object sender, EventArgs e) 
  45.     { 
  46.         //在會(huì)話結(jié)束時(shí)運(yùn)行的代碼。 
  47.         // 注意: 只有在 Web.config 文件中的 sessionstate 模式設(shè)置為 
  48.         // InProc 時(shí),才會(huì)引發(fā) Session_End 事件。如果會(huì)話模式 
  49.         //設(shè)置為 StateServer 或 SQLServer,則不會(huì)引發(fā)該事件。 
  50.  
  51.     } 
  52.        
  53. </script> 
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
ASP.NET MVC請(qǐng)求處理管道生命周期的19個(gè)關(guān)鍵環(huán)節(jié)(1-6)
Asp.net頁面之間傳遞參數(shù)的幾種方法
ASP.NET頁面之間傳值的方法,我試過的有5種方法,現(xiàn)在總結(jié)如下:
Asp.net頁面之間的傳值 - Study
ASP.NET頁面間傳值的幾種方式
asp.net WebForm頁面間傳值方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服