Skip to content

Commit 3af5c5b

Browse files
committed
* ApplicationLogs will be cleared after 10 minutes
* Fixed a threading issue with the LogWindow
1 parent cc8e645 commit 3af5c5b

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

MemPlus/Classes/LOG/LogController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Timers;
34

45
namespace MemPlus.Classes.LOG
56
{
@@ -57,9 +58,20 @@ public class LogController
5758
/// <summary>
5859
/// Initialize a new LogController object
5960
/// </summary>
60-
internal LogController()
61+
/// <param name="clearInterval">The interval for when ApplicationLog objects should automatically be cleared</param>
62+
internal LogController(int clearInterval)
6163
{
6264
_logList = new List<Log>();
65+
66+
Timer logTimer = new Timer();
67+
logTimer.Elapsed += OnTimedEvent;
68+
logTimer.Interval = clearInterval;
69+
logTimer.Enabled = true;
70+
}
71+
72+
private void OnTimedEvent(object sender, ElapsedEventArgs e)
73+
{
74+
ClearLogs(LogType.Application);
6375
}
6476

6577
/// <summary>

MemPlus/Windows/LogWindow.xaml.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ public LogWindow(LogController logController, LogType logType)
4444

4545
private void LogTypeClearedEvent(List<Log> clearedList)
4646
{
47-
foreach (Log l in clearedList)
47+
Dispatcher.Invoke(() =>
4848
{
49-
LsvLogs.Items.Remove(l);
50-
}
49+
foreach (Log l in clearedList)
50+
{
51+
LsvLogs.Items.Remove(l);
52+
}
53+
});
5154
}
5255

5356
private void FillLogView()
@@ -61,12 +64,18 @@ private void FillLogView()
6164
private void LogDeletedEvent(Log log)
6265
{
6366
if (log.LogType != _logType) return;
64-
LsvLogs.Items.Remove(log);
67+
Dispatcher.Invoke(() =>
68+
{
69+
LsvLogs.Items.Remove(log);
70+
});
6571
}
6672

6773
private void LogsClearedEvent()
6874
{
69-
LsvLogs.Items.Clear();
75+
Dispatcher.Invoke(() =>
76+
{
77+
LsvLogs.Items.Clear();
78+
});
7079
}
7180

7281
private void LogAddedEvent(Log log)

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ namespace MemPlus.Windows
1414
/// </summary>
1515
public partial class MainWindow
1616
{
17-
1817
private readonly RamController _ramController;
1918
private readonly LogController _logController;
2019

2120
private bool _rmEnabledBeforeInvisible;
2221

2322
public MainWindow()
2423
{
25-
_logController = new LogController();
24+
_logController = new LogController(600000);
2625
_logController.AddLog(new ApplicationLog("Initializing MainWindow"));
2726

2827
InitializeComponent();

0 commit comments

Comments
 (0)