asp.Netタイミング実行タスクコードタイミング収集データ

2671 ワード

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Timers;
using System.Net;
using System.IO;
using System.Text;
using System.Threading;

namespace DTcms.Web
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            //      
            System.Timers.Timer myTimer = new System.Timers.Timer(1000);
            myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
            myTimer.Enabled = true;
            myTimer.AutoReset = true;
        }

        void myTimer_Elapsed(object source, ElapsedEventArgs e)
        {
            try
            {
                //Log.SaveNote(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")   ":AutoTask is Working!");
                YourTask();
            }
            catch (Exception ee)
            {
             //   Log.SaveException(ee);
            }
        }

        void YourTask()
        {
            if (DateTime.Now.ToString("HH:mm") == "15:20")
            {
                //            
                DTcms.BLL.article bll = new DTcms.BLL.article();
                DTcms.Model.article_news model = new Model.article_news();
                model.title = "     " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                model.channel_id = 1;
                model.category_id = 1;
                bll.Add(model);
            }
        }


        protected void Application_End(object sender, EventArgs e)
        {
          //  Log.SaveNote(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")   ":Application End!");
 
            //        ,   IIS            
            Thread.Sleep(1000);
            //      web  ,            aspx          ,      Ap            plication_Start
            string url = "http://cpzy.net/e.aspx";
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            Stream receiveStream = myHttpWebResponse.GetResponseStream();//        
            
        }
   }
}