程序定时执行 我想要在每天晚上8点 执行一段代码只能用代码执行 目前 我不会设置执行时间请各位能给出详细代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 额.....给你代码你改下~~<%@ Application Language="C#" %><%@ import Namespace="System.IO" %> <%@ import Namespace="System.Data.SqlClient" %><script runat="server"> void Application_Start(object sender, EventArgs e) { //在应用程序启动时运行的代码 System.Timers.Timer myTimer = new System.Timers.Timer(); // myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent); myTimer.Interval = 1000; myTimer.Enabled = true; } void Application_End(object sender, EventArgs e) { //在应用程序关闭时运行的代码 //下面的代码是关键,可解决IIS应用程序池自动回收的问题 Thread.Sleep(1000); //这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start //string url = "http://www.qumiao.com";手机主题 string url = "http://localhost:82/111.aspx"; HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 } void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e) { //在新会话启动时运行的代码 Session["userName"] = ""; Session["Ohter"]=""; } void Session_End(object sender, EventArgs e) { //在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 // InProc 时,才会引发 Session_End 事件。如果会话模式 //设置为 StateServer 或 SQLServer,则不会引发该事件。 } private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e) { string strweek = e.SignalTime.DayOfWeek.ToString(); //int inthour = e.SignalTime.Hour; //int intminute = e.SignalTime.Minute; int intSecond = e.SignalTime.Second; string sweek = "Thursday"; //int ihour = 21; //int iminute = 00; int isecond = 00; if (strweek == sweek && intSecond == isecond) { string connectionString = ConfigurationManager.ConnectionStrings["TestforInsertConnectionString"].ConnectionString; SqlConnection myConnection = new SqlConnection(connectionString); string sql = "insert into line(ID,LName)values('20','line01')"; SqlCommand myCommand = new SqlCommand(sql, myConnection); myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); } } </script> 谢谢Lovely_baby 我试试~ 如何给list<T>分页! GridView 的列绑定字段(DataField)如何编程修改? flash JS 图片链接问题 各位前辈!谁会在ASP.net页面中使用MSChart这个控件!请各位介绍下!小弟在线等!不胜感激 简单问题,帮帮忙啊 动态生成控件的事件问题 高难度报表问题,高手进,up顶者有分 想一个好办法 treeview或web services問題 dataset能当作参数返回吗 网站并发访问时出现问题!高分求解!! 求一个存储过程+SQLHeper返回DateReader的例子。
给你代码你改下~~<%@ Application Language="C#" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Data.SqlClient" %><script runat="server"> void Application_Start(object sender, EventArgs e)
{
//在应用程序启动时运行的代码
System.Timers.Timer myTimer = new System.Timers.Timer();
// myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
myTimer.Interval = 1000;
myTimer.Enabled = true;
}
void Application_End(object sender, EventArgs e)
{
//在应用程序关闭时运行的代码
//下面的代码是关键,可解决IIS应用程序池自动回收的问题
Thread.Sleep(1000);
//这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start
//string url = "http://www.qumiao.com";手机主题
string url = "http://localhost:82/111.aspx";
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 }
void Application_Error(object sender, EventArgs e)
{
//在出现未处理的错误时运行的代码 } void Session_Start(object sender, EventArgs e)
{
//在新会话启动时运行的代码
Session["userName"] = "";
Session["Ohter"]="";
} void Session_End(object sender, EventArgs e)
{
//在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式
//设置为 StateServer 或 SQLServer,则不会引发该事件。 }
private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
{
string strweek = e.SignalTime.DayOfWeek.ToString();
//int inthour = e.SignalTime.Hour;
//int intminute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
string sweek = "Thursday";
//int ihour = 21;
//int iminute = 00;
int isecond = 00; if (strweek == sweek && intSecond == isecond)
{ string connectionString = ConfigurationManager.ConnectionStrings["TestforInsertConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
string sql = "insert into line(ID,LName)values('20','line01')";
SqlCommand myCommand = new SqlCommand(sql, myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
} }
</script>
我试试~