1.定时任务:
gloabl.asax文件Application_Start()方法注册:
System.Timers.Timer t = new System.Timers.Timer(theInterval); //单位毫秒 t.Elapsed += new ElapsedEventHandler((s, e) => { theSend(); }); t.AutoReset = true; t.Enabled = true;
2.获取气象数据:后台处理获取
DtWeather entity = new DtWeather(); string url = "http://www.nmc.cn。。。。。。。。。"; var request = (HttpWebRequest)WebRequest.Create(url); var response = (HttpWebResponse)request.GetResponse(); string date = new StreamReader(response.GetResponseStream()).ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); Info datainfo = js.Deserialize<Info>(date);
3.定时执行新增方法:
DateTime now = DateTime.Now; DateTime start = DateTime.Parse("9:55:00"); DateTime end = DateTime.Parse("10:00:00"); if ((now> start) &&(now< end)) { //定时执行新增方法 DtWeatherDal da = new DtWeatherDal(); da.Add(); }
http://www.nmc.cn/f/rest/real/58339