Skip to content

Commit a73a64b

Browse files
committed
Removed FireAndForget in place of InvokeAsync to ensure render thread and JS play nice together
1 parent 4316ed2 commit a73a64b

8 files changed

Lines changed: 21 additions & 37 deletions

File tree

src/EventLogExpert/Components/EventTable.razor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ protected override async Task OnInitializedAsync()
4747
{
4848
SelectedEventState.Select(s => s.SelectedEvents);
4949

50-
SubscribeToAction<EventTableAction.SetActiveTable>(action => ScrollToSelectedEvent().AndForget());
51-
SubscribeToAction<EventTableAction.LoadColumnsCompleted>(action => RegisterTableEventHandlers().AndForget());
52-
SubscribeToAction<EventTableAction.UpdateCombinedEvents>(action => ScrollToSelectedEvent().AndForget());
53-
SubscribeToAction<EventTableAction.UpdateDisplayedEvents>(action => ScrollToSelectedEvent().AndForget());
50+
SubscribeToAction<EventTableAction.SetActiveTable>(action => InvokeAsync(ScrollToSelectedEvent));
51+
SubscribeToAction<EventTableAction.LoadColumnsCompleted>(action => InvokeAsync(RegisterTableEventHandlers));
52+
SubscribeToAction<EventTableAction.UpdateCombinedEvents>(action => InvokeAsync(ScrollToSelectedEvent));
53+
SubscribeToAction<EventTableAction.UpdateDisplayedEvents>(action => InvokeAsync(ScrollToSelectedEvent));
5454

5555
_eventTableState = EventTableState.Value;
5656

src/EventLogExpert/ExtensionMethods.cs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
// // Copyright (c) Microsoft Corporation.
22
// // Licensed under the MIT License.
33

4-
using EventLogExpert.Eventing.Helpers;
54
using System.Reflection;
65
using System.Runtime.Serialization;
7-
using System.Text;
86

97
namespace EventLogExpert;
108

119
internal static class ExtensionMethods
1210
{
13-
internal static void AndForget(this Task task, ITraceLogger? logger = null)
11+
extension(DateTime time)
1412
{
15-
if (!task.IsCompleted || task.IsFaulted) { _ = ForgetAwaited(task, logger); }
13+
internal DateTime ConvertTimeZone(TimeZoneInfo? destinationTime) =>
14+
destinationTime is null ? time : TimeZoneInfo.ConvertTimeFromUtc(time, destinationTime);
1615

17-
static async Task ForgetAwaited(Task task, ITraceLogger? logger = null)
18-
{
19-
try
20-
{
21-
await task.ConfigureAwait(false);
22-
}
23-
catch (Exception ex)
24-
{
25-
logger?.Trace(ex.Message);
26-
}
27-
}
16+
internal DateTime ConvertTimeZoneToUtc(TimeZoneInfo? destinationTime) =>
17+
destinationTime is null ? time : TimeZoneInfo.ConvertTimeToUtc(time, destinationTime);
2818
}
2919

30-
internal static DateTime ConvertTimeZone(this DateTime time, TimeZoneInfo? destinationTime) =>
31-
destinationTime is null ? time : TimeZoneInfo.ConvertTimeFromUtc(time, destinationTime);
32-
33-
internal static DateTime ConvertTimeZoneToUtc(this DateTime time, TimeZoneInfo? destinationTime) =>
34-
destinationTime is null ? time : TimeZoneInfo.ConvertTimeToUtc(time, destinationTime);
35-
3620
internal static string ToFullString(this Enum value)
3721
{
3822
var memberAttribute = value.GetType().GetField(value.ToString())?

src/EventLogExpert/MainPage.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ await MainThread.InvokeOnMainThreadAsync(() =>
111111
fluxorDispatcher.Dispatch(new FilterCacheAction.LoadFilters());
112112
fluxorDispatcher.Dispatch(new FilterGroupAction.LoadGroups());
113113

114-
ProcessCommandLine();
114+
_ = ProcessCommandLine();
115115
}
116116

117117
public void Dispose()
@@ -437,7 +437,7 @@ private void PopulateOtherLogsMenu()
437437
CreateFlyoutMenu(OpenOtherLogsFlyoutSubitem, names);
438438
}
439439

440-
private void ProcessCommandLine()
440+
private async Task ProcessCommandLine()
441441
{
442442
var args = Environment.GetCommandLineArgs();
443443

@@ -446,7 +446,7 @@ private void ProcessCommandLine()
446446
switch (arg)
447447
{
448448
case not null when arg.EndsWith(".evtx"):
449-
OpenLog(arg, PathType.FilePath).AndForget();
449+
await OpenLog(arg, PathType.FilePath);
450450
break;
451451
}
452452
}

src/EventLogExpert/Shared/Components/DebugLogModal.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected internal override async Task Open()
2121

2222
protected override void OnInitialized()
2323
{
24-
TraceLogger.DebugLogLoaded += () => Open().AndForget();
24+
TraceLogger.DebugLogLoaded += () => InvokeAsync(Open);
2525

2626
base.OnInitialized();
2727
}

src/EventLogExpert/Shared/Components/Filters/FilterCacheModal.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed partial class FilterCacheModal
2525

2626
protected override void OnInitialized()
2727
{
28-
SubscribeToAction<FilterCacheAction.OpenMenu>(action => Open().AndForget());
28+
SubscribeToAction<FilterCacheAction.OpenMenu>(action => InvokeAsync(Open));
2929

3030
base.OnInitialized();
3131
}
@@ -44,7 +44,7 @@ private void AddFilter(string filter)
4444
IsEnabled = true
4545
}));
4646

47-
Close().AndForget();
47+
InvokeAsync(Close);
4848
}
4949

5050
private async Task ExportFavorites()

src/EventLogExpert/Shared/Components/Filters/FilterGroup.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public sealed partial class FilterGroup
2828
private void ApplyFilters()
2929
{
3030
Dispatcher.Dispatch(new FilterPaneAction.ApplyFilterGroup(Group));
31-
Parent.Close().AndForget();
31+
InvokeAsync(Parent.Close);
3232
}
3333

34-
private void CopyGroup() => Clipboard.SetTextAsync(Group.Filters.Count() > 1 ?
34+
private void CopyGroup() => Clipboard.SetTextAsync(Group.Filters.Count > 1 ?
3535
string.Join(" || ", Group.Filters.Select(filter => $"({filter.Comparison.Value})")) :
36-
Group.Filters.First().Comparison.Value);
36+
Group.Filters[0].Comparison.Value);
3737

3838
private async Task ExportGroup()
3939
{

src/EventLogExpert/Shared/Components/Filters/FilterGroupModal.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed partial class FilterGroupModal
2323

2424
protected override void OnInitialized()
2525
{
26-
SubscribeToAction<FilterGroupAction.OpenMenu>(action => Open().AndForget());
26+
SubscribeToAction<FilterGroupAction.OpenMenu>(action => InvokeAsync(Open));
2727

2828
base.OnInitialized();
2929
}

src/EventLogExpert/Shared/Components/SettingsModal.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected internal override async Task Close()
5656

5757
protected override void OnInitialized()
5858
{
59-
Settings.Loaded += () => Load().AndForget();
59+
Settings.Loaded += () => InvokeAsync(Load);
6060

6161
base.OnInitialized();
6262
}
@@ -101,7 +101,7 @@ private async Task ImportDatabase()
101101

102102
await AlertDialogService.ShowAlert("Import Successful", message, "OK");
103103

104-
Close().AndForget();
104+
await InvokeAsync(Close);
105105
}
106106
catch (Exception ex)
107107
{

0 commit comments

Comments
 (0)