コード例 #1
0
        private void RunRealPing()
        {
            int pid = -1;

            try
            {
                string msg = string.Empty;

                pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
                if (pid < 0)
                {
                    _updateFunc(_selecteds[0].indexId, UIRes.I18N("OperationFailed"));
                    return;
                }

                //Thread.Sleep(5000);
                List <Task> tasks = new List <Task>();
                foreach (var it in _selecteds)
                {
                    if (!it.allowTest)
                    {
                        continue;
                    }
                    if (it.configType == EConfigType.Custom)
                    {
                        continue;
                    }
                    tasks.Add(Task.Run(() =>
                    {
                        try
                        {
                            WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
                            int responseTime  = -1;
                            string status     = GetRealPingTime(_config.constItem.speedPingTestUrl, webProxy, out responseTime);
                            string output     = Utils.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;

                            _config.GetVmessItem(it.indexId)?.SetTestResult(output);
                            _updateFunc(it.indexId, output);
                        }
                        catch (Exception ex)
                        {
                            Utils.SaveLog(ex.Message, ex);
                        }
                    }));
                    //Thread.Sleep(100);
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                Utils.SaveLog(ex.Message, ex);
            }
            finally
            {
                if (pid > 0)
                {
                    _v2rayHandler.V2rayStopPid(pid);
                }
            }
        }
コード例 #2
0
        private void RunRealPing()
        {
            int pid = -1;

            try
            {
                string msg = string.Empty;

                pid = _v2rayHandler.LoadV2rayConfigString(_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);

                Thread.Sleep(100);
            }
            catch (Exception ex)
            {
                Utils.SaveLog(ex.Message, ex);
            }
            finally
            {
                if (pid > 0)
                {
                    _v2rayHandler.V2rayStopPid(pid);
                }
            }
        }
コード例 #3
0
ファイル: SpeedtestHandler.cs プロジェクト: wang-song/v2rayN
        private void RunRealPing()
        {
            int pid = -1;

            try
            {
                string msg = string.Empty;

                pid = _v2rayHandler.LoadV2rayConfigString(_config, _selecteds);
                if (pid < 0)
                {
                    _updateFunc(_selecteds[0], UIRes.I18N("OperationFailed"));
                    return;
                }

                //Thread.Sleep(5000);
                int         httpPort = _config.GetLocalPort("speedtest");
                List <Task> tasks    = new List <Task>();
                foreach (int itemIndex in _selecteds)
                {
                    if (_config.vmess[itemIndex].configType == (int)EConfigType.Custom)
                    {
                        continue;
                    }
                    tasks.Add(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) ? FormatOut(responseTime, "ms") : FormatOut(status, "");
                            _updateFunc(itemIndex, output);
                        }
                        catch (Exception ex)
                        {
                            Utils.SaveLog(ex.Message, ex);
                        }
                    }));
                    //Thread.Sleep(100);
                }
                Task.WaitAll(tasks.ToArray());
            }
            catch (Exception ex)
            {
                Utils.SaveLog(ex.Message, ex);
            }
            finally
            {
                if (pid > 0)
                {
                    _v2rayHandler.V2rayStopPid(pid);
                }
            }
        }