Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
Get result from Task.WhenAll

I have multiple tasks returning the same object type that I want to call using Task.WhenAll(new[]{t1,t2,t3}); and read the results.

When I try using

Task<List<string>> all = await Task.WhenAll(new Task[] { t, t2 }).ConfigureAwait(false);

I get a compiler error

Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task<System.Collections.Generic.List<string>>

both tasks are calling method similar the this.

private Task<List<string>> GetFiles(string path)
{
    files = new List<string>();
    return  Task.Run(() =>
    {
       //remove for brevity 
        return files;
    });
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Looks like you are using the overload of WaitAll() that doesn't return a value. If you make the following changes, it should work.

List<string>[] all = await Task.WhenAll(new Task<List<string>>[] { t, t2 })
                               .ConfigureAwait(false);
over 4 years ago · Santiago Trujillo Denunciar

0

The return type of WhenAll is a task whose result type is an array of the individual tasks' result type, in your case Task<List<string>[]>

When used in an await expression, the task will be "unwrapped" into its result type, meaning that the type of your "all" variable should be List<string>[]

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda