private void RunRealPing() { try { string msg = string.Empty; Global.reloadV2ray = true; _v2rayHandler.LoadV2ray(_config, _selecteds); Thread.Sleep(5000); var httpPort = _config.GetLocalPort("speedtest"); for (int k = 0; k < _selecteds.Count; k++) { int index = _selecteds[k]; if (_config.vmess[index].configType == (int)EConfigType.Custom) { continue; } try { var webProxy = new WebProxy(Global.Loopback, httpPort + index); int responseTime = -1; var status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime); if (!Utils.IsNullOrEmpty(status)) { _updateFunc(index, string.Format("{0}", status)); } else { _updateFunc(index, string.Format("{0}ms", responseTime)); } } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } Thread.Sleep(100); } Global.reloadV2ray = true; _v2rayHandler.LoadV2ray(_config); Thread.Sleep(100); } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } }
private void RunRealPing() { try { string msg = string.Empty; Global.reloadV2ray = true; _v2rayHandler.LoadV2ray(_config, _selecteds); Thread.Sleep(5000); int httpPort = _config.GetLocalPort("speedtest"); Task[] tasks = new Task[_selecteds.Count]; int i = -1; foreach (int itemIndex in _selecteds) { if (_config.vmess[itemIndex].configType == (int)EConfigType.Custom) { continue; } i++; tasks[i] = Task.Run(() => { try { WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex); int responseTime = -1; string status = GetRealPingTime(_config.speedPingTestUrl, webProxy, out responseTime); string output = Utils.IsNullOrEmpty(status) ? string.Format("{0}ms", responseTime) : string.Format("{0}", status); _updateFunc(itemIndex, output); } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } }); //Thread.Sleep(100); } Task.WaitAll(tasks); Global.reloadV2ray = true; _v2rayHandler.LoadV2ray(_config); Thread.Sleep(100); } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } }
public void RunRealPing() { try { for (int k = 0; k < _selecteds.Count; k++) { int index = _selecteds[k]; if (_config.vmess[index].configType == (int)EConfigType.Custom) { continue; } try { if (ConfigHandler.SetDefaultServer(ref _config, index) == 0) { _v2rayHandler.LoadV2ray(_config); } else { return; } Thread.Sleep(1000 * 5); int responseTime = -1; var status = GetRealPingTime(Global.SpeedPingTestUrl, out responseTime); if (!Utils.IsNullOrEmpty(status)) { _updateFunc(index, string.Format("{0}", status)); } else { _updateFunc(index, string.Format("{0}ms", responseTime)); } } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } } Thread.Sleep(1); } catch (Exception ex) { Utils.SaveLog(ex.Message, ex); } }