From 689f29d0f0b72d48d37a82d6755ec6999ff73253 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Fri, 7 Aug 2020 22:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E4=B8=BB=E7=95=8C=E9=9D=A2=E5=B8=B8?= =?UTF-8?q?=E7=94=A8UI=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Netch/Forms/MainForm.Control.cs | 18 ++++++++++++++++-- Netch/Forms/MainForm.Status.cs | 20 +++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Netch/Forms/MainForm.Control.cs b/Netch/Forms/MainForm.Control.cs index 6f1a1ab5..3c0baee2 100644 --- a/Netch/Forms/MainForm.Control.cs +++ b/Netch/Forms/MainForm.Control.cs @@ -114,6 +114,12 @@ namespace Netch.Forms public void OnBandwidthUpdated(long download) { + if (InvokeRequired) + { + BeginInvoke(new Action(OnBandwidthUpdated), download); + return; + } + try { UsedBandwidthLabel.Text = $"{i18N.Translate("Used", ": ")}{Bandwidth.Compute(download)}"; @@ -124,13 +130,20 @@ namespace Netch.Forms LastDownloadBandwidth = download; Refresh(); } - catch (Exception) + catch { + // ignored } } public void OnBandwidthUpdated(long upload, long download) { + if (InvokeRequired) + { + BeginInvoke(new Action(OnBandwidthUpdated), upload, download); + return; + } + try { if (upload < 1 || download < 1) @@ -147,8 +160,9 @@ namespace Netch.Forms LastDownloadBandwidth = download; Refresh(); } - catch (Exception) + catch { + // ignored } } diff --git a/Netch/Forms/MainForm.Status.cs b/Netch/Forms/MainForm.Status.cs index 227e1406..da3033de 100644 --- a/Netch/Forms/MainForm.Status.cs +++ b/Netch/Forms/MainForm.Status.cs @@ -22,6 +22,12 @@ namespace Netch.Forms get => _state; private set { + if (InvokeRequired) + { + BeginInvoke(new Action(() => { State = value; })); + return; + } + void StartDisableItems(bool enabled) { ServerComboBox.Enabled = @@ -61,7 +67,7 @@ namespace Netch.Forms ControlButton.Text = i18N.Translate("Stop"); StatusTextAppend(_mainController.PortInfo); - + ProfileGroupBox.Enabled = true; UsedBandwidthLabel.Visible /*= UploadSpeedLabel.Visible*/ = DownloadSpeedLabel.Visible = true; @@ -94,6 +100,12 @@ namespace Netch.Forms public void NatTypeStatusText(string text = "", string country = "") { + if (InvokeRequired) + { + BeginInvoke(new Action(NatTypeStatusText), text, country); + return; + } + if (State != State.Started) { NatTypeStatusLabel.Text = ""; @@ -162,6 +174,12 @@ namespace Netch.Forms /// public void StatusText(string text) { + if (InvokeRequired) + { + BeginInvoke(new Action(StatusText), text); + return; + } + StatusLabel.Text = i18N.Translate("Status", ": ") + text; }