多线程测试真延迟

pull/542/head
YFdyh000 5 years ago
parent 593313a684
commit aee8994c41

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using v2rayN.Mode; using v2rayN.Mode;
namespace v2rayN.Handler namespace v2rayN.Handler
@ -138,40 +139,38 @@ namespace v2rayN.Handler
_v2rayHandler.LoadV2ray(_config, _selecteds); _v2rayHandler.LoadV2ray(_config, _selecteds);
Thread.Sleep(5000); Thread.Sleep(5000);
var httpPort = _config.GetLocalPort("speedtest"); var httpPort = _config.GetLocalPort("speedtest");
foreach (int index in _selecteds) Task[] tasks = new Task[_selecteds.Count];
int i = -1;
foreach (int itemIndex in _selecteds)
{ {
if (_config.vmess[index].configType == (int)EConfigType.Custom) if (_config.vmess[itemIndex].configType == (int)EConfigType.Custom)
{ {
continue; continue;
} }
try i++;
{ tasks[i] = Task.Factory.StartNew(() => {
var webProxy = new WebProxy(Global.Loopback, httpPort + index); try
int responseTime = -1;
var status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime);
if (!Utils.IsNullOrEmpty(status))
{ {
_updateFunc(index, string.Format("{0}", status)); WebProxy webProxy = new WebProxy(Global.Loopback, httpPort + itemIndex);
int responseTime = -1;
var status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime);
string output = Utils.IsNullOrEmpty(status) ? string.Format("{0}ms", responseTime) : string.Format("{0}", status);
_updateFunc(itemIndex, output);
} }
else catch (Exception ex)
{ {
_updateFunc(index, string.Format("{0}ms", responseTime)); Utils.SaveLog(ex.Message, ex);
} }
} });
catch (Exception ex) //Thread.Sleep(100);
{
Utils.SaveLog(ex.Message, ex);
}
Thread.Sleep(100);
} }
Task.WaitAll(tasks);
Global.reloadV2ray = true; Global.reloadV2ray = true;
_v2rayHandler.LoadV2ray(_config); _v2rayHandler.LoadV2ray(_config);
Thread.Sleep(100); Thread.Sleep(100);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -286,7 +285,6 @@ namespace v2rayN.Handler
{ {
string msg = string.Empty; string msg = string.Empty;
responseTime = -1; responseTime = -1;
try try
{ {
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
@ -313,7 +311,6 @@ namespace v2rayN.Handler
msg = ex.Message; msg = ex.Message;
} }
return msg; return msg;
} }
} }
} }

@ -1459,7 +1459,7 @@ namespace v2rayN.Handler
msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), configCopy.getSummary()); msg = string.Format(UIRes.I18N("SuccessfulConfiguration"), configCopy.getSummary());
} }
catch (Exception ex) catch
{ {
msg = UIRes.I18N("FailedGenDefaultConfiguration"); msg = UIRes.I18N("FailedGenDefaultConfiguration");
return -1; return -1;

Loading…
Cancel
Save