Skip to content

Commit 7f09a58

Browse files
committed
Fix hang on unload.
1 parent b01042a commit 7f09a58

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎Torch.Server/Views/LogEventViewer.xaml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
<ComboBox x:Name="ClassFilterComboBox" Width="130" ItemsSource="{Binding LogClasses}" Margin="0,0,5,0" SelectionChanged="ClassFilterComboBox_SelectionChanged"/>
2222

2323
<Button x:Name="ResetFiltersButton" Content="Reset filters" Margin="0,0,5,0" Click="ResetFiltersButton_Click" />
24-
<!-- test log button -->
2524
<Button x:Name="ClearButton" Content="Clear table" Margin="0,0,5,0" Click="ClearButton_Click" />
25+
26+
<Button x:Name="TestButton" Content="Test log" Margin="0,0,5,0" Click="TestButton_OnClickButton_Click" Visibility="Hidden" />
27+
2628
</StackPanel>
2729

2830

‎Torch.Server/Views/LogEventViewer.xaml.cs‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using System.Windows;
66
using System.Windows.Controls;
77
using System.Windows.Input;
8+
using System.Windows.Threading;
89
using NLog;
10+
using Torch.API;
911
using Torch.Patches;
1012
using MessageBox = System.Windows.Forms.MessageBox;
1113

@@ -69,6 +71,11 @@ public LogEventViewer()
6971
//set the log level filter to the first item in the combo box
7072
LevelFilterComboBox.SelectedIndex = 0;
7173
ClassFilterComboBox.SelectedIndex = 0;
74+
75+
if (TorchServer.Instance.Config.BranchName == TorchBranchType.dev)
76+
{
77+
TestButton.Visibility = Visibility.Visible;
78+
}
7279
};
7380
}
7481

@@ -80,7 +87,7 @@ private void Unloading()
8087
private void LogEvent(LogEventInfo obj)
8188
{
8289
// Use Dispatcher.Invoke to ensure that the following code block is executed on the UI thread.
83-
Dispatcher.Invoke(() =>
90+
Dispatcher.BeginInvoke(() =>
8491
{
8592
try
8693
{
@@ -92,14 +99,14 @@ private void LogEvent(LogEventInfo obj)
9299
ClassFilterComboBox.ItemsSource = updatedClassFilters;
93100
classFilters = updatedClassFilters; // Ensure classFilters is updated for future checks.
94101
}
95-
102+
96103
AddRow(obj.Level.ToString(), obj.LoggerName, (obj.Message == "{0}" ? obj.FormattedMessage : obj.Message));
97104
}
98105
catch (Exception ex)
99106
{
100107
MessageBox.Show(ex.Message);
101108
}
102-
});
109+
}, DispatcherPriority.Background);
103110
}
104111
private void LevelFilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
105112
{
@@ -183,5 +190,10 @@ private void ClearButton_Click(object sender, RoutedEventArgs e)
183190
{
184191
((LogViewModel) DataContext).LogEvents.Clear();
185192
}
193+
194+
private void TestButton_OnClickButton_Click(object sender, RoutedEventArgs e)
195+
{
196+
_log.Error("Test error message");
197+
}
186198
}
187199
}

0 commit comments

Comments
 (0)