Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
Obtener resultado de Task.WhenAll

Tengo varias tareas que devuelven el mismo tipo de objeto al que quiero llamar usando Task.WhenAll(new[]{t1,t2,t3}); y leer los resultados.

Cuando trato de usar

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

me sale un error del compilador

No se puede convertir implícitamente el tipo 'void' a 'System.Threading.Tasks.Task<System.Collections.Generic.List<string>>

ambas tareas están llamando a un método similar a este.

 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 answers
Answer question

0

Parece que está utilizando la sobrecarga de WaitAll() que no devuelve un valor. Si realiza los siguientes cambios, debería funcionar.

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

0

El tipo de devolución de WhenAll es una tarea cuyo tipo de resultado es una matriz del tipo de resultado de las tareas individuales, en su caso Task<List<string>[]>

Cuando se usa en una expresión de espera, la tarea se "desenvolverá" en su tipo de resultado, lo que significa que el tipo de su variable "todos" debe ser List<string>[]

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!