Skip to content

Commit

Permalink
fix: reduce gui refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
gc87 committed Jan 3, 2023
1 parent 6856572 commit 72572b0
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Windows.Forms;
using System.Threading.Channels;
using Serilog;

namespace neuopc
{
Expand All @@ -33,32 +34,32 @@ public MainForm()

private void UpdateListView(List<Item> list)
{
foreach (var i in list)
try
{
try
Action<List<Item>> action = (data) =>
{

Action<Item> 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];
var subItemQuality = item.SubItems[4];
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}");
}
}

Expand All @@ -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<Item> list)
{
Action<List<Item>> action = (data) =>
try
{
MainListView.BeginUpdate();
MainListView.Items.Clear();
for (int i = 0; i < data.Count; i++)
Action<List<Item>> 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}");
}
}

Expand Down

0 comments on commit 72572b0

Please sign in to comment.