Skip to content

Commit

Permalink
Refactor Test All Server Delay Tick
Browse files Browse the repository at this point in the history
  • Loading branch information
chsbuffer committed Jan 15, 2021
1 parent aa021aa commit 7547533
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 97 deletions.
56 changes: 40 additions & 16 deletions Netch/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ private void MainForm_Load(object sender, EventArgs e)
_comboBoxNumberBoxWidth = ServerComboBox.Width / 10;

InitServer();
ServerHelper.DelayTestHelper.UpdateInterval();

ModeHelper.Load();
InitMode();
_comboBoxInitialized = true;
Expand Down Expand Up @@ -597,19 +599,28 @@ private async void ControlButton_Click(object sender, EventArgs e)
if (Global.Settings.MinimizeWhenStarted)
Minimize();

if (Global.Settings.StartedTcping)
// 自动检测延迟
_ = Task.Run(() =>
// 自动检测延迟
_ = Task.Run(() =>
{
while (State == State.Started)
{
while (State == State.Started)
bool StartedPingEnabled()
{
return Global.Settings.StartedPingInterval >= 0;
}

if (StartedPingEnabled())
{
server.Test();
// 重绘 ServerComboBox
ServerComboBox.Refresh();

Thread.Sleep(Global.Settings.StartedTcping_Interval * 1000);
}
});

if (StartedPingEnabled())
Thread.Sleep(Global.Settings.StartedPingInterval * 1000);
else
Thread.Sleep(5000);
}
});
}

#endregion
Expand All @@ -629,6 +640,9 @@ private void SettingsButton_Click(object sender, EventArgs e)
InitProfile();
}

if (ServerHelper.DelayTestHelper.Interval != Global.Settings.DetectionTick)
ServerHelper.DelayTestHelper.UpdateInterval();

if (ProfileButtons.Count != Global.Settings.ProfileCount)
InitProfile();

Expand Down Expand Up @@ -691,15 +705,25 @@ private void SpeedPictureBox_Click(object sender, EventArgs e)
Enabled = false;
StatusText(i18N.Translate("Testing"));

ServerHelper.TestDelayFinished += OnTestDelayFinished;
_ = Task.Run(ServerHelper.TestAllDelay);

void OnTestDelayFinished(object o1, EventArgs e1)
if (IsWaiting())
{
Refresh();
NotifyTip(i18N.Translate("Test done"));
ServerHelper.DelayTestHelper.TestDelayFinished += OnTestDelayFinished;
_ = Task.Run(ServerHelper.DelayTestHelper.TestAllDelay);

void OnTestDelayFinished(object o1, EventArgs e1)
{
Refresh();
NotifyTip(i18N.Translate("Test done"));

ServerHelper.TestDelayFinished -= OnTestDelayFinished;
ServerHelper.DelayTestHelper.TestDelayFinished -= OnTestDelayFinished;
Enabled = true;
StatusText();
}
}
else
{
(ServerComboBox.SelectedItem as Server)?.Test();
ServerComboBox.Refresh();
Enabled = true;
StatusText();
}
Expand Down Expand Up @@ -1024,7 +1048,7 @@ void StartDisableItems(bool enabled)

_state = value;

ServerHelper.Timer.Enabled = IsWaiting(_state);
ServerHelper.DelayTestHelper.Enabled = IsWaiting(_state);

StatusText();
switch (value)
Expand Down
78 changes: 44 additions & 34 deletions Netch/Forms/SettingForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Netch/Forms/SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ private void InitValue()
i => i > -1,
i => Global.Settings.ProfileCount = i,
Global.Settings.ProfileCount);
BindCheckBox(TcpingAtStartedCheckBox,
b => Global.Settings.StartedTcping = b,
Global.Settings.StartedTcping);
BindTextBox<int>(DetectionIntervalTextBox,
BindTextBox<int>(DetectionTickTextBox,
i => i >= 0,
i => Global.Settings.StartedTcping_Interval = i,
Global.Settings.StartedTcping_Interval);
i => Global.Settings.DetectionTick = i,
Global.Settings.DetectionTick);
BindTextBox<int>(StartedPingIntervalTextBox,
_ => true,
i => Global.Settings.StartedPingInterval = i,
Global.Settings.StartedPingInterval);

InitSTUN();

Expand Down
12 changes: 6 additions & 6 deletions Netch/Models/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public class Setting
/// </summary>
public bool CheckUpdateWhenOpened = true;

/// <summary>
/// 测试所有服务器心跳/秒
/// </summary>
public int DetectionTick = 10;

/// <summary>
/// 是否关闭窗口时退出
/// </summary>
Expand Down Expand Up @@ -230,15 +235,10 @@ public class Setting
/// </summary>
public ushort Socks5LocalPort = 2801;

/// <summary>
/// 是否启用启动后延迟测试
/// </summary>
public bool StartedTcping = false;

/// <summary>
/// 启动后延迟测试间隔/秒
/// </summary>
public int StartedTcping_Interval = 3;
public int StartedPingInterval = -1;

/// <summary>
/// 是否打开软件时启动加速
Expand Down
Loading

0 comments on commit 7547533

Please sign in to comment.