I'm quite sure this was answered but I can't find it into SO. I want to return a string from my async method, but it returns "System.Threading.Tasks.Task`1[System.String]", not the string value.
Calling code:
DBSql dBSqlSources = new DBSql(ModuleMain.CurrentDatabase.DBServer, ModuleMain.CurrentDatabase.DBDatabase);
string dataSources = dBSqlSources.GetDataSourceAsync().ToString();
My method:
public async Task<string> GetDataSourceAsync()
{
  SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
  string ServerName = string.Empty, InstanceName  =string.Empty;
  StringBuilder FullServerName = new StringBuilder(string.Empty);
  DataTable table = await Task.Run(() => instance.GetDataSources());
  foreach (DataRow row in table.Rows)
  {
    try
    {
      ServerName = row["ServerName"].ToString();
      InstanceName = row["InstanceName"].ToString();
      if (!string.IsNullOrEmpty(InstanceName))
      {
        FullServerName.Append(string.Concat(ServerName, @"\", InstanceName));
      }
    }
    catch (Exception ex)
    {
      ModuleMain._Log.AddError($"GetDataSources, {ex.Message}");
      return string.Empty;
    }
  }
  return FullServerName.ToString();
}
 
     
     
     
    