Skip to content

Commit a11e4bc

Browse files
committed
Fix Warning 'CS4014' in "UITests.App" project
The `SendLogMessage` method in the App class returns `Task` but we didn't await where it is called, i.e. in the `LogMessage` method. Thus, updating the method with async/await pattern fixes the warning.
1 parent e4e06cb commit a11e4bc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

UITests/UITests.App/App.AppService.xaml.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.Threading.Tasks;
89
using Microsoft.Toolkit.Mvvm.Messaging;
910
using UITests.App.Pages;
@@ -139,9 +140,10 @@ public async Task SendLogMessage(string level, string msg)
139140
{ "Message", msg }
140141
};
141142

142-
await _appServiceConnection.SendMessageAsync(message);
143+
var response = await _appServiceConnection.SendMessageAsync(message);
143144

144145
// TODO: do we care if we have a problem here?
146+
Debug.WriteLine(response);
145147
}
146148

147149
private static bool TryGetValueAndLog(ValueSet message, string key, out string value)
@@ -164,7 +166,7 @@ private static bool TryGetValueAndLog(ValueSet message, string key, out string v
164166
return true;
165167
}
166168

167-
private Dictionary<string, Func<ValueSet, Task<ValueSet>>> _customCommands = new();
169+
private readonly Dictionary<string, Func<ValueSet, Task<ValueSet>>> _customCommands = new();
168170

169171
internal void RegisterCustomCommand(string id, Func<ValueSet, Task<ValueSet>> customCommandFunction)
170172
{

UITests/UITests.App/TestInterop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void Error(string format, params object[] args)
2828
LogMessage("Error", "[Error] " + format, args);
2929
}
3030

31-
private static void LogMessage(string level, string format, object[] args)
31+
private static async void LogMessage(string level, string format, object[] args)
3232
{
3333
// string.Format() complains if we pass it something with braces, even if we have no arguments.
3434
// To account for that, we'll escape braces if we have no arguments.
@@ -43,7 +43,7 @@ private static void LogMessage(string level, string format, object[] args)
4343

4444
// Send back to Test Harness via AppService
4545
// TODO: Make this a cleaner connection/pattern
46-
_ = ((App)Application.Current).SendLogMessage(level, message);
46+
await ((App)Application.Current).SendLogMessage(level, message).ConfigureAwait(false);
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)