Ping ui error

This commit is contained in:
kshman 2021-03-21 04:18:25 +09:00
parent f731188c8f
commit c47063a0c0

View file

@ -1332,64 +1332,45 @@ namespace DutyContent.Tab
} }
} }
private Color PingColorSelectDialog(Color current) private void PingColorWorker(int index, Button button)
{ {
Color color = (Color)WorkerAct.Invoker(new WorkerAct.ObjectReturnerDelegate(() => Color color = (Color)WorkerAct.Invoker(new WorkerAct.ObjectReturnerDelegate(() =>
{ {
var dg = new ColorDialog() var dg = new ColorDialog()
{ {
AnyColor = true, AnyColor = true,
Color = current, Color = DcConfig.Duty.PingColors[index],
}; };
return dg.ShowDialog() == DialogResult.OK ? dg.Color : current; return dg.ShowDialog() == DialogResult.OK ? dg.Color : DcConfig.Duty.PingColors[index];
})); }));
return color; if (DcConfig.Duty.PingColors[index] != color)
{
button.BackColor = color;
DcConfig.Duty.PingColors[index] = color;
SaveConfig();
}
} }
private void BtnPingColor1_Click(object sender, EventArgs e) private void BtnPingColor1_Click(object sender, EventArgs e)
{ {
var ret = PingColorSelectDialog(DcConfig.Duty.PingColors[0]); PingColorWorker(0, btnPingColor1);
if (DcConfig.Duty.PingColors[0] != ret)
{
btnPingColor1.BackColor = ret;
DcConfig.Duty.PingColors[0] = ret;
SaveConfig();
}
} }
private void BtnPingColor2_Click(object sender, EventArgs e) private void BtnPingColor2_Click(object sender, EventArgs e)
{ {
var ret = PingColorSelectDialog(DcConfig.Duty.PingColors[1]); PingColorWorker(1, btnPingColor2);
if (DcConfig.Duty.PingColors[1] != ret)
{
btnPingColor2.BackColor = ret;
DcConfig.Duty.PingColors[1] = ret;
SaveConfig();
}
} }
private void BtnPingColor3_Click(object sender, EventArgs e) private void BtnPingColor3_Click(object sender, EventArgs e)
{ {
var ret = PingColorSelectDialog(DcConfig.Duty.PingColors[2]); PingColorWorker(2, btnPingColor3);
if (DcConfig.Duty.PingColors[2] != ret)
{
btnPingColor3.BackColor = ret;
DcConfig.Duty.PingColors[2] = ret;
SaveConfig();
}
} }
private void BtnPingColor4_Click(object sender, EventArgs e) private void BtnPingColor4_Click(object sender, EventArgs e)
{ {
var ret = PingColorSelectDialog(DcConfig.Duty.PingColors[2]); PingColorWorker(3, btnPingColor4);
if (DcConfig.Duty.PingColors[2] != ret)
{
btnPingColor4.BackColor = ret;
DcConfig.Duty.PingColors[2] = ret;
SaveConfig();
}
} }
// //
@ -1400,20 +1381,23 @@ namespace DutyContent.Tab
var conns = DcConfig.Connections.CopyConnection(); var conns = DcConfig.Connections.CopyConnection();
if (conns.Length == 0) if (conns.Length == 0)
{
_overlay.ResetStat();
return; return;
}
long rtt = 0; long rtt = 0;
double loss = 0.0; double loss = 0.0;
foreach (var row in conns) foreach (var row in conns)
{ {
var p = CalcPing(row.RemoteAddress); var (Rtt, Loss) = CalcPing(row.RemoteAddress);
if (rtt < p.Rtt) if (rtt < Rtt)
rtt = p.Rtt; rtt = Rtt;
if (loss < p.Loss) if (loss < Loss)
loss = p.Loss; loss = Loss;
} }
//MesgLog.L("Ping: {0}, {1}%", rtt, loss); //MesgLog.L("Ping: {0}, {1}%", rtt, loss);