void webClient_DownloadDataCompleted(object sender, DownloadStringCompletedEventArgs e) { try { int day = 8; List <DateTime> depart = new List <DateTime>(); List <DateTime> arrive = new List <DateTime>(); try { string the_page = e.Result; if (the_page.IndexOf("This timetable is valid for ") > 0) { the_page = the_page.Substring(the_page.IndexOf("This timetable is valid for ")); the_page = the_page.Substring(the_page.IndexOf(">") + 1); } else if (the_page.IndexOf("This service does not have a timetable for ") > 0) { the_page = the_page.Substring(the_page.IndexOf("This service does not have a timetable for ") + "This service does not have a timetable for ".Length); } the_page = the_page.Substring(the_page.IndexOf(" ") + 1); string day_string = the_page.Substring(0, the_page.IndexOf("<")).Trim().Trim('.'); String month_string = day_string.Substring(day_string.IndexOf(" ")).Trim(); int month = -1; switch (month_string) { case "Jan": month = 1; break; case "Feb": month = 2; break; case "Mar": month = 3; break; case "Apr": month = 4; break; case "May": month = 5; break; case "Jun": month = 6; break; case "Jul": month = 7; break; case "Aug": month = 8; break; case "Sep": month = 9; break; case "Oct": month = 10; break; case "Nov": month = 11; break; case "Dec": month = 12; break; } DateTime daydt = new DateTime(DateTime.Now.Year, month, int.Parse(day_string.Substring(0, day_string.IndexOf(" ")))); day = (daydt.DayOfYear - DateTime.Now.DayOfYear) % 365; if (day != 0) { day = (int)daydt.DayOfWeek; if (day == 0) { day = 7; } } the_page = the_page.Substring(the_page.IndexOf(@"<div id=""" + Trip.Direction)); List <String> bfgds = getTimeTableRows(the_page); foreach (String timeTableRow in bfgds) { if (timeTableRow.IndexOf("name=\"" + Trip.From.Id + "\"") != -1) { depart = getTrainTimes(timeTableRow, depart, day); } else if (timeTableRow.IndexOf("name=\"" + Trip.To.Id + "\"") != -1) { arrive = getTrainTimes(timeTableRow, arrive, day); } } } catch (Exception err) { if ((day == 6 || day == 7) && Trip.Line.Id == "MEL") { StringEventHandler.SetDepartTimes(day, "No trains." + err); } } ParseData(depart, arrive, day); } catch (WebException err) { WebResponse herp = err.Response; } }