62,047
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Timers;
using System.Threading;
using System.Diagnostics;
namespace gift
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
public Global()
{
InitializeComponent();
}
protected void Application_Start(Object sender, EventArgs e)
{
Pub.UpFileClass.WriteContentToFile(Pub.GetSet.SitePath+"log/"+ DateTime.Now.ToShortDateString() +".txt" ,"["+DateTime.Now+"] 系统开始运行.",true,"utf-8");
System.Timers.Timer myTimer = new System.Timers.Timer();
myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
myTimer.Interval = Pub.GetSet.AutoDelTimerInterval;
myTimer.AutoReset = true;
myTimer.Enabled = true;
Pub.UpFileClass.WriteContentToFile(Pub.GetSet.SitePath+"log/"+ DateTime.Now.ToShortDateString() +".txt" ,"["+DateTime.Now+"]"+myTimer.Interval,true,"utf-8");
}
........(省略若干代码)
private void myTimer_Elapsed(object source, ElapsedEventArgs e)
{
ThreadStart threadDelegat = new ThreadStart(DelExpiredBusiness);
Thread myThread = new Thread(threadDelegat);
if (Application["DelExpiredBusinessState"].ToString() != "Running")
{
myThread.Start();
}
}
/// <summary>
/// 删除过期信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void DelExpiredBusiness()
{
Application.Lock();
Application["DelExpiredBusinessState"] = "Running";
Application.UnLock();
SqlParameter[] param = new SqlParameter[]{new SqlParameter("@ExpiredDay",SqlDbType.Int),new SqlParameter("@RETURN_VALUE",SqlDbType.Int)};
param[0].Value = 90;
param[1].Direction = ParameterDirection.ReturnValue;
SqlDataReader rd = gift.Data.Provider.Global.getDataReader("sp_Business_expried_day",param);
while(rd.Read())
{
try
{
Pub.UpFileClass.DeleteFile(rd["BPic"].ToString());
Pub.UpFileClass.DeleteFile(rd["BHPic"].ToString());
}
catch
{
}
}
rd.Close();
gift.Data.Provider.Global.NonQuery("delete from business where DATEDIFF(DAY,BValidate,GETDATE())>90");
Application.Lock();
Application["DelExpiredBusinessState"] = "End";
Application.UnLock();
}
#region Web 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
}
#endregion
}
}
void Application_Start(object sender, EventArgs e)
{
// 應用程式啟動時執行的程式碼
System.Timers.Timer timer = new System.Timers.Timer(1000 *60);
//AutoReset 属性为 true 时,每隔指定时间循环一次;
//如果为 false,则只执行一次。
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
System.Timers.Timer timer = new System.Timers.Timer(1000 *60);