private static void ScheduleGetAllRecentContestsJsonCallback(Object state) { try { HttpWebRequest request = HttpWebRequest.CreateHttp(ConfigurationManager.RecentContestURL); request.Timeout = REQUEST_TIMEOUT; request.BeginGetResponse(ar => { HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar); using (Stream stream = response.GetResponseStream()) { StreamReader sr = new StreamReader(stream); String content = RecentContestManager.ProcessRecentContestsJsonContent(sr.ReadToEnd()); if (!String.IsNullOrEmpty(content)) { RecentContestCache.SetRecentContestCache(content);//设置缓存 } } }, request); } catch (System.Exception) { ;//Do Nothing } }
private static async Task <String> GetAllRecentContestsJsonFromWebAsync() { HttpClient client = new HttpClient(); client.Timeout = TimeSpan.FromMilliseconds(REQUEST_TIMEOUT); String content = await client.GetStringAsync(ConfigurationManager.RecentContestURL); return(RecentContestManager.ProcessRecentContestsJsonContent(content)); }