public void loadChat() { bool completed = false; using (WebClientTimeOut wc = new WebClientTimeOut(2000)) { wc.Headers.Add("user-agent", "BlitzChat"); wc.DownloadStringCompleted += delegate(object a, DownloadStringCompletedEventArgs b) { if (b.Error == null) { try { JObject messages = JsonConvert.DeserializeObject <JObject>(b.Result); if (messages != null) { updateMessages(messages); } } catch (Exception e) { Debug.Print("Chat messages deserializing exception: " + e.Message); } } completed = true; }; wc.DownloadStringAsync(new Uri(string.Format(chatUrl, chatId))); while (!completed) { Thread.Sleep(20); } } }
public override void Execute() { if (state == DownloadState.loading) { ErrorStr = "loader is downloading" + config.URL; Error(); } state = DownloadState.loading; if (Async) { CoroutineCall.Call(DownloadAsync); } else { using (WebClientTimeOut client = new WebClientTimeOut()) { try { client.DownloadFile(config.URL, config.CacheFilePath); } catch (Exception e) { ErrorStr = e.ToString(); Error(); return; } Complete(); } } }
public string getViewers() { try { using (WebClientTimeOut wc = new WebClientTimeOut(500)) { string info = wc.DownloadString(String.Format(chatUsers, chatId)); JObject jObj = JsonConvert.DeserializeObject <JObject>(info); JArray arr = (JArray)jObj["text"]; return(arr.Count.ToString()); } } catch (Exception e) { Debug.Print("Exception on parsing userId from gamersTV: " + e.Message); return("0"); } }
public string getViewers() { try { using (WebClientTimeOut wc = new WebClientTimeOut(1000)) { string info = wc.DownloadString(String.Format(channelInfoUrl, channelName)); int startIndex = info.IndexOf("{\"userinfo\""); info = info.Substring(startIndex, info.Length - startIndex - 1); JObject jObj = JsonConvert.DeserializeObject <JObject>(info); return(jObj["viewers"]["cnt"].ToString()); } } catch (Exception e) { Debug.Print("Exception on parsing viewers on gohaTV: " + e.Message); return("0"); } }