I have the following code:
public static async void PopulateMetrics()
{
await Task.Run(() =>
{
if (App.CPUSpeed == 0)
{
var stopWatch = Stopwatch.StartNew();
stopWatch.Start();
ArrayList al = new ArrayList(); for (int i = 0; i < 5000000; i++) al.Add("hello");
App.CPUSpeed = 20000 / stopWatch.ElapsedMilliseconds;
}
});
}
The IDE is telling me that the async method should not return void. Would making it return Task<bool>
and returning true fix this but is that needed?
Also would there be any difference in calling this between:
_ = PopulateMetrics()
and
await PopulateMetrics()
Here is what I have for the calling method. Note that for all except the PopulateMetrics, I have exception handling in each of the async methods.
if (Connectivity.NetworkAccess == NetworkAccess.Internet)
{
if (Settings.Rev == REV.No && (new[] { 15, 30, 50 }).Contains(Settings.Trk2))
{
_ = ReviewAppAsync(Settings.Trk2);
}
if (App.devIsPhysical && (new[] { 10, 20, 30 }).Contains(Settings.Trk2))
{
_ = CheckLatestVersion();
}
_ = Helper.PopulateMetrics();
_ = Helper.LogStart();
}