private async Task<List<PingReply>> PingAsync()
{
Ping pingSender = new Ping();
var tasks = serverNames.Select(ip => pingSender.SendPingAsync(ip, 2000));
var results = await Task.WhenAll(tasks);
return results.ToList();
}
My question is how would I execute this method?
I've tried
List<string> data = PingAsync();
But I get this error message
Error CS0029 Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Collections.Generic.List<System.Net.NetworkInformation.PingReply>>' to 'System.Collections.Generic.List<string>' ServerManager
I am trying to ping servers and update the UI so we can monitor servers.
I've also tried these
Task<PingReply> longRunningTask = PingAsync();
PingReply result = await longRunningTask;
Error
Severity Code Description Project File Line Suppression State Error CS4033 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. ServerManager
Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'System.Threading.Tasks.Task>' to 'System.Threading.Tasks.Task' ServerManager