private void Initialization() { //监听IP数量 AgentPool.IpsChange += (nums) => { this.Invoke(new Action(() => lblIpsNums.Text = $"IP数量:{nums}")); }; AgentPool.AddAgentIp(JsonConfig <AgentIp> .GetSiteConfigs()); AgentPool.SaveIps(); RefreshRoom(); return; Task.Run(async() => { while (true) { for (int i = 0; i < 10; i++) { await Task.Delay(2000); try { using (HttpWebResponse httpWebResponse = await CCHttpRequest.CreateGetHttpResponseAsync("http://http.tiqu.alicdns.com/getip3?num=20&type=2&pro=&city=0&yys=0&port=2&pack=74963&ts=1&ys=1&cs=1&lb=1&sb=0&pb=45&mr=2®ions=&gm=4")) { //获取返回内容 string json = await httpWebResponse.GetResponseStream().ReadAllTextAsync(); MsgInfo(json); //将JSON字符串转换为dynamic类型 dynamic obj = JsonConvert.DeserializeObject <dynamic>(json); if (obj.success != true) { continue; } List <AgentIp> ips = obj.data.ToObject <List <AgentIp> >(); AgentPool.AddAgentIp(ips); AgentPool.SaveIps(); return; } } catch (Exception ex) { Console.WriteLine($"【获取IP错误】:{ex.Message}"); MsgError($"【获取IP错误】:{ex.Message}"); } } return; await Task.Delay(10000); } }); }