Skip to content

Commit f047451

Browse files
author
BRUNER Patrick
committed
multithreaded filter readded
1 parent b97762e commit f047451

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

src/LogExpert.Core/Classes/Filter/FilterStarter.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public FilterStarter (ColumnizerCallback callback, int minThreads)
6565

6666
#region Public methods
6767

68-
public async void DoFilter (FilterParams filterParams, int startLine, int maxCount, ProgressCallback progressCallback)
68+
public async Task DoFilter (FilterParams filterParams, int startLine, int maxCount, ProgressCallback progressCallback)
6969
{
7070
FilterResultLines.Clear();
7171
LastFilterLinesList.Clear();
@@ -85,8 +85,11 @@ public async void DoFilter (FilterParams filterParams, int startLine, int maxCou
8585
}
8686

8787
var workStartLine = startLine;
88+
8889
_progressLineCount = 0;
8990
_progressCallback = progressCallback;
91+
92+
var tasks = new List<Task>();
9093
while (workStartLine < startLine + maxCount)
9194
{
9295
if (workStartLine + interval > maxCount)
@@ -100,11 +103,14 @@ public async void DoFilter (FilterParams filterParams, int startLine, int maxCou
100103

101104
_logger.Info(CultureInfo.InvariantCulture, "FilterStarter starts worker for line {0}, lineCount {1}", workStartLine, interval);
102105

103-
var filter = await Task.Run(() => DoWork(filterParams, workStartLine, interval, ThreadProgressCallback)).ConfigureAwait(false);
104-
FilterDoneCallback(filter);
106+
var capturedStartLine = workStartLine;
107+
var capturedInterval = interval;
108+
109+
tasks.Add(Task.Run(() => DoWork(filterParams, capturedStartLine, capturedInterval, ThreadProgressCallback)));
105110
workStartLine += interval;
106111
}
107112

113+
await Task.WhenAll(tasks).ConfigureAwait(false);
108114
MergeResults();
109115
}
110116

src/LogExpert.UI/Controls/LogWindow/LogWindow.cs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,9 @@ private void OnSelectionChangedTriggerSignal (object sender, EventArgs e)
13321332
{
13331333
if (IsMultiFile)
13341334
{
1335-
MethodInvoker invoker = DisplayCurrentFileOnStatusline;
1336-
_ = invoker.BeginInvoke(null, null);
1335+
//MethodInvoker invoker = DisplayCurrentFileOnStatusline;
1336+
_ = Task.Run(DisplayCurrentFileOnStatusline);
1337+
//_ = invoker.BeginInvoke(null, null);
13371338
}
13381339
else
13391340
{
@@ -2936,12 +2937,12 @@ private void LoadingFinished ()
29362937
private void LogEventWorker ()
29372938
{
29382939
Thread.CurrentThread.Name = "LogEventWorker";
2939-
while (true)
2940+
while (!cts.Token.IsCancellationRequested)
29402941
{
29412942
//_logger.Debug($"Waiting for signal");
29422943
_ = _logEventArgsEvent.WaitOne();
29432944
//_logger.Debug($"Wakeup signal received.");
2944-
while (true)
2945+
while (!cts.Token.IsCancellationRequested)
29452946
{
29462947
LogEventArgs e;
29472948
//var lastLineCount = 0;
@@ -2973,9 +2974,24 @@ private void LogEventWorker ()
29732974
// }
29742975
//}
29752976

2976-
_ = Invoke(UpdateGrid, [e]);
2977-
CheckFilterAndHighlight(e);
2978-
_timeSpreadCalc.SetLineCount(e.LineCount);
2977+
if (IsDisposed || Disposing || _waitingForClose)
2978+
{
2979+
return;
2980+
}
2981+
else
2982+
{
2983+
try
2984+
{
2985+
_ = Invoke(UpdateGrid, [e]);
2986+
}
2987+
catch (ObjectDisposedException)
2988+
{
2989+
return;
2990+
}
2991+
2992+
CheckFilterAndHighlight(e);
2993+
_timeSpreadCalc.SetLineCount(e.LineCount);
2994+
}
29792995
}
29802996
}
29812997
}
@@ -3132,8 +3148,7 @@ private void CheckFilterAndHighlight (LogEventArgs e)
31323148
var (suppressLed, stopTail, setBookmark, bookmarkComment) = GetHighlightActions(matchingList);
31333149
if (setBookmark)
31343150
{
3135-
SetBookmarkFx fx = SetBookmarkFromTrigger;
3136-
_ = fx.BeginInvoke(i, bookmarkComment, null, null);
3151+
_ = Task.Run(() => SetBookmarkFromTrigger(i, bookmarkComment));
31373152
}
31383153

31393154
if (stopTail && _guiStateArgs.FollowTail)
@@ -3142,7 +3157,8 @@ private void CheckFilterAndHighlight (LogEventArgs e)
31423157
FollowTailChanged(false, true);
31433158
if (firstStopTail && wasFollow)
31443159
{
3145-
_ = Invoke(new SelectLineFx(SelectAndEnsureVisible), [i, false]);
3160+
//_ = Invoke(new SelectLineFx(SelectAndEnsureVisible), [i, false]);
3161+
_ = Task.Run(() => SelectAndEnsureVisible(i, false));
31463162
firstStopTail = false;
31473163
}
31483164
}
@@ -3180,8 +3196,9 @@ private void CheckFilterAndHighlight (LogEventArgs e)
31803196
var (suppressLed, stopTail, setBookmark, bookmarkComment) = GetHighlightActions(matchingList);
31813197
if (setBookmark)
31823198
{
3183-
SetBookmarkFx fx = SetBookmarkFromTrigger;
3184-
_ = fx.BeginInvoke(i, bookmarkComment, null, null);
3199+
//SetBookmarkFx fx = SetBookmarkFromTrigger;
3200+
_ = Task.Run(() => SetBookmarkFromTrigger(i, bookmarkComment));
3201+
//_ = fx.BeginInvoke(i, bookmarkComment, null, null);
31853202
}
31863203

31873204
if (stopTail && _guiStateArgs.FollowTail)
@@ -3190,7 +3207,8 @@ private void CheckFilterAndHighlight (LogEventArgs e)
31903207
FollowTailChanged(false, true);
31913208
if (firstStopTail && wasFollow)
31923209
{
3193-
_ = Invoke(new SelectLineFx(SelectAndEnsureVisible), [i, false]);
3210+
//_ = Invoke(new SelectLineFx(SelectAndEnsureVisible), [i, false]);
3211+
_ = Task.Run(() => SelectAndEnsureVisible(i, false));
31943212
firstStopTail = false;
31953213
}
31963214
}
@@ -3223,8 +3241,9 @@ private void LaunchHighlightPlugins (IList<HighlightEntry> matchingList, int lin
32233241
var plugin = PluginRegistry.PluginRegistry.Instance.FindKeywordActionPluginByName(entry.ActionEntry.PluginName);
32243242
if (plugin != null)
32253243
{
3226-
ActionPluginExecuteFx fx = plugin.Execute;
3227-
_ = fx.BeginInvoke(entry.SearchText, entry.ActionEntry.ActionParam, callback, CurrentColumnizer, null, null);
3244+
//ActionPluginExecuteFx fx = plugin.Execute;
3245+
_ = Task.Run(() => plugin.Execute(entry.SearchText, entry.ActionEntry.ActionParam, callback, CurrentColumnizer));
3246+
//_ = fx.BeginInvoke(entry.SearchText, entry.ActionEntry.ActionParam, callback, CurrentColumnizer, null, null);
32283247
}
32293248
}
32303249
}
@@ -4359,11 +4378,8 @@ private async void FilterSearch (string text)
43594378

43604379
var settings = ConfigManager.Settings;
43614380

4362-
//FilterFx fx = settings.preferences.multiThreadFilter ? MultiThreadedFilter : new FilterFx(Filter);
43634381
FilterFxAction = settings.Preferences.MultiThreadFilter ? MultiThreadedFilter : Filter;
4364-
4365-
//Task.Run(() => fx.Invoke(_filterParams, _filterResultList, _lastFilterLinesList, _filterHitList));
4366-
var filterFxActionTask = Task.Run(() => Filter(_filterParams, _filterResultList, _lastFilterLinesList, _filterHitList)).ConfigureAwait(false);
4382+
var filterFxActionTask = Task.Run(() => FilterFxAction(_filterParams, _filterResultList, _lastFilterLinesList, _filterHitList)).ConfigureAwait(false);
43674383

43684384
await filterFxActionTask;
43694385
FilterComplete();
@@ -4388,7 +4404,7 @@ private void MultiThreadedFilter (FilterParams filterParams, List<int> filterRes
43884404
OnRegisterCancelHandler(cancelHandler);
43894405
long startTime = Environment.TickCount;
43904406

4391-
fs.DoFilter(filterParams, 0, _logFileReader.LineCount, FilterProgressCallback);
4407+
fs.DoFilter(filterParams, 0, _logFileReader.LineCount, FilterProgressCallback).GetAwaiter().GetResult();
43924408

43934409
long endTime = Environment.TickCount;
43944410

@@ -6609,7 +6625,7 @@ public IList<HighlightMatchEntry> FindHighlightMatches (ITextValueMemory line)
66096625
GetHighlightEntryMatches(line, _currentHighlightGroup.HighlightEntryList, resultList);
66106626
}
66116627

6612-
lock (_tempHighlightEntryList)
6628+
lock (_tempHighlightEntryListLock)
66136629
{
66146630
GetHighlightEntryMatches(line, _tempHighlightEntryList, resultList);
66156631
}
@@ -7751,8 +7767,9 @@ public void PatternStatisticSelectRange (PatternArgs patternArgs)
77517767

77527768
public void PatternStatistic (PatternArgs patternArgs)
77537769
{
7754-
var fx = new PatternStatisticFx(TestStatistic);
7755-
_ = fx.BeginInvoke(patternArgs, null, null);
7770+
//var fx = new PatternStatisticFx(TestStatistic);
7771+
_ = Task.Run(() => TestStatistic(patternArgs));
7772+
//_ = fx.BeginInvoke(patternArgs, null, null);
77567773
}
77577774

77587775
public void ExportBookmarkList ()

0 commit comments

Comments
 (0)