c# 4.0 - Task.wait in task array -


i need execute line completed after tasks completed.i thought task.waitall(tasks) take care after executing callback method completed line gets executed.is there way block main thread untill task aray completes it.

taskpprcessor.batchstart(definition)

public void batchstart(list<taskdefinition> definition)         {             int = 0;             tasks = new task[definition.count];             definition.foreach((a) =>             {                  tasks[i] = task<taskresult>.factory.startnew(() => (taskresult)a.methodtocall.dynamicinvoke(a.arguments));                 tasks[i].continuewith(task => runtaskretobjresultins((task<taskresult>)task, a.completemethod));                     i++;              });             task.waitall(tasks); console.writeline("completed"); } 

i try this:

public void batchstart(list<taskdefinition> definition) {     task.waitall(         definition.select             (a => task<taskresult>.factory.startnew(                 () => (taskresult)a.methodtocall.dynamicinvoke(a.arguments)).continuewith(task => runtaskretobjresultins((task<taskresult>)task, a.completemethod))             ).toarray()         );     console.writeline("completed"); } 

i think problem continuewith returns new task, , that's 1 want wait for. you're waiting original tasks not continuation.


Comments

Popular posts from this blog

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -