//timerEmail.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;/// <summary>
/// TimerEmail 的摘要说明
/// </summary>
public sealed class TimerEmail
{
public TimerEmail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private System.Threading.Timer _timer;
private int _interval;
public int Interval {
get { return _interval; }
set { _interval = value; }
}
public void Initialize()
{
Interval = 120;
_timer = new System.Threading.Timer(TimerCallback, null, System.Threading.Timeout.Infinite, Interval * 1000);
}
private void StartAgent()
{
_timer.Change(0, Interval * 1000);
}
private void StopAgent()
{
_timer.Change(System.Threading.Timeout.Infinite, Interval * 1000);
}
private static void TimerCallback(object state)
{
DataTable table = new MemberDB().GetNoLoginMembers().Tables[0];
// DataTable table1 = new OrderDB().GetNoBackScoreOrders();
try
{
EmailDetails emailDetails = new EmailDB().GetEmailDetails(11);
/* for (int i = 0; i < table.Rows.Count; i++)
{
// WebUtils.SendEMail(table.Rows[i].Cells[0], emailDetails.Title, emailDetails.Centent);
WebUtils.SendEMail("[email protected]", emailDetails.Title, emailDetails.Centent);
}*/
new ArticleDB().AddArticle("测试定时器", "测试定时器", 1, DateTime.Now);
WebUtils.SendEMail("[email protected]", emailDetails.Title, emailDetails.Centent);
}
catch
{
}
finally
{
table.Clear();
// table1.Clear();
}
}}//Global.asax里是这样写的
private static TimerEmail _token_update_agent = new TimerEmail();
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
_token_update_agent.Initialize();
}
我跟踪了,这句代码执行了: _timer = new System.Threading.Timer(TimerCallback, null, System.Threading.Timeout.Infinite, Interval * 1000);
为什么TimerCallback(object state)就没执行呢?
初学定时器,做过的帮我看看,vs2005
或者有没有现成的代码供我学习一下啰!先谢了!
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Threading;/// <summary>
/// TimerEmail 的摘要说明
/// </summary>
public sealed class TimerEmail
{
public TimerEmail()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private System.Threading.Timer _timer;
private int _interval;
public int Interval {
get { return _interval; }
set { _interval = value; }
}
public void Initialize()
{
Interval = 120;
_timer = new System.Threading.Timer(TimerCallback, null, System.Threading.Timeout.Infinite, Interval * 1000);
}
private void StartAgent()
{
_timer.Change(0, Interval * 1000);
}
private void StopAgent()
{
_timer.Change(System.Threading.Timeout.Infinite, Interval * 1000);
}
private static void TimerCallback(object state)
{
DataTable table = new MemberDB().GetNoLoginMembers().Tables[0];
// DataTable table1 = new OrderDB().GetNoBackScoreOrders();
try
{
EmailDetails emailDetails = new EmailDB().GetEmailDetails(11);
/* for (int i = 0; i < table.Rows.Count; i++)
{
// WebUtils.SendEMail(table.Rows[i].Cells[0], emailDetails.Title, emailDetails.Centent);
WebUtils.SendEMail("[email protected]", emailDetails.Title, emailDetails.Centent);
}*/
new ArticleDB().AddArticle("测试定时器", "测试定时器", 1, DateTime.Now);
WebUtils.SendEMail("[email protected]", emailDetails.Title, emailDetails.Centent);
}
catch
{
}
finally
{
table.Clear();
// table1.Clear();
}
}}//Global.asax里是这样写的
private static TimerEmail _token_update_agent = new TimerEmail();
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
_token_update_agent.Initialize();
}
我跟踪了,这句代码执行了: _timer = new System.Threading.Timer(TimerCallback, null, System.Threading.Timeout.Infinite, Interval * 1000);
为什么TimerCallback(object state)就没执行呢?
初学定时器,做过的帮我看看,vs2005
或者有没有现成的代码供我学习一下啰!先谢了!
解决方案 »
- GridView 无法居中
- ASP.NET可以做视频播放吗?可以做到像优酷那样吗?可以支持多种格式吗?要用到什么技术?
- <急>请问如何用FindControl获取网页里动态生成的html类的textbox?
- 大家做ASP。NET程序怎么和美工分工合作?
- 请问自定义控件的属性值可以想办法和CSS文件里的设置联系起来么?
- DataGrid页脚》加页数??
- 当网页关闭时,如何将用户数据保存到数据库中!!!????
- 关于一个不知道跟页面缓冲有没有关系的问题
- 怎样把DataReader读出来的字段值付给Byte[]类型?
- who can give me a example for asp multiple files upload?
- 请问怎么实现动态列表?比如说在TextBox输入“1”,相关的以“1”开头的数据则显示?B/S结构的
- datagrid ,没有数据时的显示问题
改成0表示立即调用方法
你写的表示永远不调用