//private void getEveryHours(object sender, System.Timers.ElapsedEventArgs e) //{ // if (!string.IsNullOrEmpty(citylist.Text) & !string.IsNullOrEmpty(dataPath.Text)) // { // Action<string, string> getRealtime = autoGet; // this.BeginInvoke(getRealtime, citylist.Text, dataPath.Text); // } //} private void autoGet(string cityList, string dataPath) { timer.Interval = 3600000; EnvironmentalData.getCityHttp(); StreamReader sr = new StreamReader(cityList); StreamWriter sw = new StreamWriter(dataPath, true); while (!sr.EndOfStream) { string tempstr = sr.ReadLine(); string[] cityhttp = tempstr.Split(new string[] { ";", ";" }, StringSplitOptions.RemoveEmptyEntries); List <string[]> cityDataList = EnvironmentalData.getRealtimeData(cityhttp[1]); foreach (var item in cityDataList) { sw.Write(cityhttp[0] + ";"); for (int i = 0; i < item.Length; i++) { sw.Write(item[i] + ";"); } sw.Write("\r\n"); } } sr.Close(); sw.Close(); }
//private DateTime pretime = new DateTime(); //private string cityListTXTPath = string.Empty; private void button1_Click(object sender, EventArgs e) { int afterMinutes = 0; if (!checkBox1.Checked) { if (!string.IsNullOrEmpty(dataPath.Text)) { if (!timer.Enabled) { List <string> MonitorSitUrl = EnvironmentalData.getCityHttp(); foreach (var item in MonitorSitUrl) { List <string[]> data = EnvironmentalData.getRealtimeData(item); } // Action<DateTime, DateTime, string, string> getdata02 = new Action<DateTime, DateTime, string, string>(getDay); //getDay(tempTime, tempTime, filePath + "\\cityList.txt", ""); // getdata02.BeginInvoke(tempTime, tempTime, filePath + "\\cityList.txt", "", null, null); //Action<string, string> getRealtime = new Action<string, string>(autoGet); //string path = Path.GetDirectoryName(dataPath.Text); //getRealtime.BeginInvoke(path + "\\cityList.txt", dataPath.Text.Trim(), null, null); ////this.BeginInvoke(getRealtime, path+"\\cityList.txt", dataPath.Text); //timer.Enabled = true; //timer.Interval = 3600000 ; //timer.AutoReset = true; //timer.Elapsed += new System.Timers.ElapsedEventHandler(getEveryHours); } } } else { if (afterTime.Text != null & int.TryParse(afterTime.Text.Trim(), out afterMinutes)) { try { int time = Convert.ToInt32(afterTime); timer.Interval = time * 60000; } catch (Exception) { timer.Interval = 3600000; } timer.Enabled = true; timer.AutoReset = true; // timer.Elapsed += new System.Timers.ElapsedEventHandler(getEveryHours); } } }