Skip to content

Commit 8d9ecbe

Browse files
blackspherefollowerqdot
authored andcommitted
Fixing a thread deadlock bug in the log control
1 parent 2fb22e1 commit 8d9ecbe

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Buttplug.Components.Controls/ButtplugLogControl.xaml.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using NLog;
1414
using NLog.Config;
1515
using NLog.Targets;
16+
using System.Collections.Specialized;
1617

1718
namespace Buttplug.Components.Controls
1819
{
@@ -39,14 +40,25 @@ protected override void Write(LogEventInfo aLogEvent)
3940
{
4041
try
4142
{
42-
Dispatcher.FromThread(_winThread).Invoke(() =>
43+
if (_winThread != Dispatcher.CurrentDispatcher.Thread)
44+
{
45+
Dispatcher.FromThread(_winThread).Invoke(() =>
46+
{
47+
_logs.Add(Layout.Render(aLogEvent));
48+
while (_logs.Count > MaxLogs)
49+
{
50+
_logs.RemoveAt(0);
51+
}
52+
});
53+
}
54+
else
4355
{
4456
_logs.Add(Layout.Render(aLogEvent));
4557
while (_logs.Count > MaxLogs)
4658
{
4759
_logs.RemoveAt(0);
4860
}
49-
});
61+
}
5062
}
5163
catch (TaskCanceledException)
5264
{

0 commit comments

Comments
 (0)