asp.net 线程定时器(Timer )的使用
2010-06-02 00:11
417 查看
using System; using System.Web.UI.WebControls; using System.Threading; namespace test { public partial class _Default : System.Web.UI.Page { public static Label lb; protected void Page_Load(object sender, EventArgs e) { //Thread thread = new Thread(new ThreadStart(dowork)); //System.Threading.Timer t = new System.Threading.Timer(new System.Threading.TimerCallback(dowork), null, 450, 0); //Timeout //thread.Start(); Label1.Text = DateTime.Now.ToString(); _Default foo = new _Default(); _Default.lb = Label3; foo.Go(); Label2.Text = DateTime.Now.ToString(); } void Go() { TimerCallback timerDelegate = new TimerCallback(dowork); AutoResetEvent autoEvent = new AutoResetEvent(false); System.Threading.Timer workingTimer = new System.Threading.Timer(timerDelegate, autoEvent, 0, 3000); autoEvent.WaitOne(3000, false); workingTimer.Dispose(); } static void dowork(object stateInfo) { //AutoResetEvent autoEvent = (AutoResetEvent)stateInfo; //没有使用,这里写出来仅说明参数 stateInfo 的用途 System.Threading.Thread.Sleep(2000); if (lb.Text.Length > 0) { lb.Text += "<br />" + DateTime.Now.ToString(); } else { lb.Text = DateTime.Now.ToString(); } } } }
相关文章推荐
- .NET Framework中定时器timer的单线程与多线程使用讲解
- .NET Framework中定时器timer的单线程与多线程使用讲解
- 自己开发能在asp.net项目正常使用的定时器WebTimer,让定时器听话起来
- .NET Framework中定时器timer的单线程与多线程使用讲解
- asp.net中Timer定时器在web中无刷新的使用
- 自己开发能在asp.net项目正常使用的定时器WebTimer,让定时器听话起来
- asp.net mvc下使用FluentScheduler 后台任务定时器
- 在asp.net中要不使用其他插件的情况下只能使用定时器来检查, 并执行任务.
- java中使用线程实现Timer(定时器)原理和源码
- [原创] ASP.NET 应用程序中使用定时器
- Asp.Net定时发送邮件方法----(使用线程的方法)-asp.net关注
- ASP.NET Core 新建线程中使用依赖注入的问题
- 终止线程 Response.End 在Asp.net 里面的正确使用
- 使用队列和线程对现有asp.net动态页处理进行资源控制
- 在 ASP.NET 中使用计时器(Timer)
- 关于C#线程中使用定时器timer无效
- java中使用线程实现Timer(定时器)原理和源码
- java中使用线程实现Timer(定时器)原理和源码
- 使用ASP.NET创建线程实例教程
- asp.net Timer的使用方法