日期:2014-05-18  浏览次数:20445 次

计划任务
我在网上搜索了很多资料
关于说asp.net的计划任务
因为都是租的别人的虚拟空间
所以不可能使用windows计划任务
我也试着写了一个计划任务,可是没有实现,请大家给指点一下
代码如下:
C# code

<script runat="server">
    DateTime a ;
    DateTime b ;
    DateTime c = Convert.ToDateTime(DateTime.Now.TimeOfDay.ToString());
    int Minute = (int)System.DateTime.Now.Minute;

    void Application_Start(object sender, EventArgs e) 
    {
        // 在应用程序启动时运行的代码     
        //定义定时器     //1000表示1秒的意思     
        System.Timers.Timer timer = new System.Timers.Timer(1000 * 60);
        timer.Elapsed += new System.Timers.ElapsedEventHandler(_采集数据);
        timer.Enabled = true;
        timer.AutoReset = true;

    }


    void _采集数据(object sender, System.Timers.ElapsedEventArgs e)
    {
        //采集山东开奖数据
        a = Convert.ToDateTime("09:05:00.0000000");
        b = Convert.ToDateTime("22:00:00.0000000");
        string[] sd = _采集开奖号码(url_sd);
        if (c > a && c < b && Minute % 10 == 8)
            _插入开奖数据("山东", sd[0], sd[1] + " " + sd[2] + " " + sd[3] + " " + sd[4] + " " + sd[5], " ");

        //采集重庆开奖数据
        string[] cq = _采集开奖号码(url_cq);
        a = Convert.ToDateTime("09:00:00.0000000");
        b = Convert.ToDateTime("23:05:00.0000000");
        if (c > a && c < b && Minute % 10 == 3)
            _插入开奖数据("重庆", cq[0], cq[1] + " " + cq[2] + " " + cq[3] + " " + cq[4] + " " + cq[5], " ");

        //采集江西开奖数据
        a = Convert.ToDateTime("09:12:00.0000000");
        b = Convert.ToDateTime("22:05:00.0000000");
        string[] jx = _采集开奖号码(url_jx);
        if (c > a && c < b && Minute % 12 == 2)
            _插入开奖数据("江西", jx[0], jx[1] + " " + jx[2] + " " + jx[3] + " " + jx[4] + " " + jx[5], " ");

        //采集广东开奖数据
        string[] gd = _采集开奖号码(url_gd);
        a = Convert.ToDateTime("09:12:00.0000000");
        b = Convert.ToDateTime("23:05:00.0000000");
        if (c > a && c < b && Minute % 12 == 2)
            _插入开奖数据("广东", gd[0], gd[1] + " " + gd[2] + " " + gd[3] + " " + gd[4] + " " + gd[5], " ");
    }

    public string url_sd = "http://www.kuaicaile.com/sd11y/index.jhtml";
    public string url_gd = "http://www.kuaicaile.com/gd11x5/index.jhtml";
    public string url_jx = "http://www.kuaicaile.com/jxdlc/index.jhtml";
    public string url_cq = "http://www.kuaicaile.com/cq11x5/index.jhtml";



    public string[] _采集开奖号码(string url)
    {
        string[] datas; //用于存储期号及5位开奖数据
        string substring1 = "justOpenIssueNo='";
        int a1 = 17;
        int b1 = 14;
        string substring2 = "justOpenIssue='";
        int a2 = 15;
        int b2 = 8;
        //获取5位开奖数据
        System.Net.WebClient wc = new System.Net.WebClient();
        string data = Encoding.UTF8.GetString(wc.DownloadData(string.Format(url)));
        data = data.Substring(data.IndexOf(substring1) + a1, b1);
        string[] strs = data.Split(',');
        Array.Sort(strs);


        //获取期号
        string qihao = Encoding.UTF8.GetString(wc.DownloadData(string.Format(url)));
        qihao = qihao.Substring(qihao.IndexOf(substring2) + a2, b2);
        qihao = "20" + qihao;

        datas = new string[] { qihao, strs[0].ToString(), strs[1].ToString(), strs[2].ToString(), strs[3].ToString(), strs[4].ToString() };
        return datas;
    }

    public void _插入开奖数据(string city, string qihao, string data, string Bool)
    {
        
                         播放WMV有关问题