zoukankan
html css js c++ java
ASP.NET(C#) 定时执行一段代码
在Global.asax启动一条线程就ok了,下面是启动线程定时写文件的例子
Global.asax
C# code
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
//
在应用程序启动时运行的代码
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
//
在应用程序关闭时运行的代码
29
30
}
31
32
void
Application_Error(
object
sender, EventArgs e)
33
{
34
//
在出现未处理的错误时运行的代码
35
36
}
37
38
void
Session_Start(
object
sender, EventArgs e)
39
{
40
//
在新会话启动时运行的代码
41
42
}
43
44
void
Session_End(
object
sender, EventArgs e)
45
{
46
//
在会话结束时运行的代码。
47
//
注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
48
//
InProc 时,才会引发 Session_End 事件。如果会话模式
49
//
设置为 StateServer 或 SQLServer,则不会引发该事件。
50
51
}
52
53
</
script
>
54
查看全文
相关阅读:
[转]SP 2010: How To – Event Receivers and Custom Error Pages
sharepoint ServerTemplate values
SPSiteDataQuery不完全使用手册(转)
jQuery EasyUI 提示框(Messager)用法
单选按钮 点击value值自动把单选按钮选中
easy ui tabs 顶部绑定事件
jquery 中的 $("#id") 与 document.getElementById("id") 的区别
jquery ajax 的data 存表单的值
JSP中用include标签动态引入其它文件报错
Js获取当前日期时间及其它操作
原文地址:https://www.cnblogs.com/top5/p/1633538.html
最新文章
图片延迟加载效果lazyload插件
购买m9历程
minwidth、maxwidth、minheight、maxheight在IE6下兼容的解决办法
js获取屏幕的高宽度
PHP操作Mongodb API 及使用类 封装好的MongoDB操作类
HTML5之placeholder的优雅解决方案
PHP中的ob_start用法详解
Twitter Storm 实时数据处理框架分析总结
iframe自适应高度完美版解决DOM元素高度变化问题
php实现记住用户名和自动登录
热门文章
apache重写url去掉index.php
Twitter Storm:开源实时Hadoop
PHP5 mysqli 教程
异常:Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out
div 拖动
Sharepoint 2010 SPListItem的显示或编辑页面删除后自定义操作
Sharepoint EventHandler 实现弹出错误消息
js的打印分页
SharePoint 2010中添加HttpModule
Sharepoint 日历项 禁止拖拽
Copyright © 2011-2022 走看看