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; }