From 72572b0eeed83cb9f9995142f3d08711d1eb09c4 Mon Sep 17 00:00:00 2001 From: gc87 Date: Tue, 3 Jan 2023 16:39:42 +0800 Subject: [PATCH] fix: reduce gui refresh --- MainForm.cs | 76 +++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/MainForm.cs b/MainForm.cs index 72cf0c4..648c961 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Windows.Forms; using System.Threading.Channels; +using Serilog; namespace neuopc { @@ -33,14 +34,13 @@ public MainForm() private void UpdateListView(List list) { - foreach (var i in list) + try { - try + Action> action = (data) => { - - Action action = (data) => + foreach (var i in data) { - int index = data.ClientHandle; + int index = i.ClientHandle; var items = MainListView.Items; var item = items[index]; var subItemValue = item.SubItems[3]; @@ -48,17 +48,18 @@ private void UpdateListView(List list) var subItemError = item.SubItems[5]; var subItemTs = item.SubItems[6]; - subItemValue.Text = Convert.ToString(data.Value); - subItemQuality.Text = data.Quality.ToString(); - subItemError.Text = data.Error.ToString(); - subItemTs.Text = Convert.ToString(data.Timestamp); - }; + subItemValue.Text = Convert.ToString(i.Value); + subItemQuality.Text = i.Quality.ToString(); + subItemError.Text = i.Error.ToString(); + subItemTs.Text = Convert.ToString(i.Timestamp); + } + }; - Invoke(action, i); - } - catch - { - } + Invoke(action, list); + } + catch (Exception exception) + { + Log.Error($"update list view error: {exception.Message}"); } } @@ -82,42 +83,43 @@ private void UpdateDAStatusLabel(DaMsg msg) Invoke(action, msg); } - catch + catch (Exception exception) { + Log.Error($"update status lable error: {exception.Message}"); } } private void ResetListView(List list) { - Action> action = (data) => + try { - MainListView.BeginUpdate(); - MainListView.Items.Clear(); - for (int i = 0; i < data.Count; i++) + Action> action = (data) => { - ListViewItem lvi = new ListViewItem(); - lvi.Text = data[i].Name.ToString(); // handle - lvi.SubItems.Add(data[i].Type.ToString()); // type - lvi.SubItems.Add(data[i].Rights.ToString()); // rights - lvi.SubItems.Add(""); // value - lvi.SubItems.Add(""); // quality - lvi.SubItems.Add(""); // error - lvi.SubItems.Add(""); // timestamp - lvi.SubItems.Add(data[i].ClientHandle.ToString()); // handle - MainListView.Items.Add(lvi); - } - MainListView.EndUpdate(); - - }; + MainListView.BeginUpdate(); + MainListView.Items.Clear(); + for (int i = 0; i < data.Count; i++) + { + ListViewItem lvi = new ListViewItem(); + lvi.Text = data[i].Name.ToString(); // handle + lvi.SubItems.Add(data[i].Type.ToString()); // type + lvi.SubItems.Add(data[i].Rights.ToString()); // rights + lvi.SubItems.Add(""); // value + lvi.SubItems.Add(""); // quality + lvi.SubItems.Add(""); // error + lvi.SubItems.Add(""); // timestamp + lvi.SubItems.Add(data[i].ClientHandle.ToString()); // handle + MainListView.Items.Add(lvi); + } + MainListView.EndUpdate(); + }; - try - { Invoke(action, list); } - catch + catch (Exception exception) { + Log.Error($"reset list view error: {exception.Message}"); } }