Skip to content

Commit 21a88c7

Browse files
committed
fix: 进一步防止阻塞
1 parent 2890d50 commit 21a88c7

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

llcomNext/LLCOM/Views/DataViews/TerminalView.axaml.cs

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,34 @@ private void Control_OnLoaded(object? sender, RoutedEventArgs e)
5353
{
5454
if (_dataChanged)
5555
{
56+
_dataChanged = false; // 重置标记
57+
var tempLines = new List<List<TerminalBlock>>();
5658
lock (_terminalBlocks)
5759
{
58-
// 执行更新逻辑
59-
//清空文本
60-
MainTextBlock.Inlines!.Clear();
61-
foreach (var line in _terminalBlocks)
60+
//克隆数据
61+
tempLines.AddRange(CloneAllLines(_terminalBlocks));
62+
}
63+
64+
// 执行更新逻辑
65+
//清空文本
66+
MainTextBlock.Inlines!.Clear();
67+
foreach (var line in tempLines)
68+
{
69+
foreach (var block in line)
6270
{
63-
foreach (var block in line)
71+
//添加块
72+
var run = new Run(block.Text)
6473
{
65-
//添加块
66-
var run = new Run(block.Text)
67-
{
68-
[!Span.ForegroundProperty] = new Binding(block.ForegroundBindingName) { Source = Utils.Setting },
69-
[!Span.BackgroundProperty] = new Binding(block.BackgroundBindingName) { Source = Utils.Setting },
70-
FontWeight = block.IsBold ? FontWeight.Bold : FontWeight.Normal,
71-
FontStyle = block.IsItalic ? FontStyle.Italic : FontStyle.Normal,
72-
TextDecorations = block.IsUnderLine ? TextDecorations.Underline : null,
73-
};
74-
MainTextBlock.Inlines.Add(run);
75-
}
76-
MainTextBlock.Inlines.Add(new LineBreak());
74+
[!Span.ForegroundProperty] = new Binding(block.ForegroundBindingName) { Source = Utils.Setting },
75+
[!Span.BackgroundProperty] = new Binding(block.BackgroundBindingName) { Source = Utils.Setting },
76+
FontWeight = block.IsBold ? FontWeight.Bold : FontWeight.Normal,
77+
FontStyle = block.IsItalic ? FontStyle.Italic : FontStyle.Normal,
78+
TextDecorations = block.IsUnderLine ? TextDecorations.Underline : null,
79+
};
80+
MainTextBlock.Inlines.Add(run);
7781
}
82+
MainTextBlock.Inlines.Add(new LineBreak());
7883
}
79-
_dataChanged = false; // 重置标记
8084
}
8185
};
8286
_updateTimer.Start();
@@ -125,16 +129,24 @@ private void TerminalChangedEvent(object? sender, List<List<TerminalBlock>> e)
125129
lock (_terminalBlocks)
126130
{
127131
_terminalBlocks.Clear();
128-
foreach (var line in e)
132+
//克隆数据
133+
_terminalBlocks.AddRange(CloneAllLines(e));
134+
}
135+
_dataChanged = true;
136+
}
137+
138+
private List<List<TerminalBlock>> CloneAllLines(List<List<TerminalBlock>> lines)
139+
{
140+
var newLines = new List<List<TerminalBlock>>();
141+
foreach (var line in lines)
142+
{
143+
var newLine = new List<TerminalBlock>();
144+
foreach (var block in line)
129145
{
130-
var newLine = new List<TerminalBlock>();
131-
foreach (var block in line)
132-
{
133-
newLine.Add((TerminalBlock)block.Clone());
134-
}
135-
_terminalBlocks.Add(newLine);
146+
newLine.Add((TerminalBlock)block.Clone());
136147
}
148+
newLines.Add(newLine);
137149
}
138-
_dataChanged = true;
150+
return newLines;
139151
}
140152
}

0 commit comments

Comments
 (0)