我想要在每天晚上8点  执行一段代码只能用代码执行 
目前  我不会设置执行时间请各位能给出详细代码

解决方案 »

  1.   

    额.....
    给你代码你改下~~<%@ 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>
      

  2.   

    谢谢Lovely_baby 
    我试试~