Hi All,
I am using the below code to Call 5 methods in Parallel and then waiting to received response from all the methods before proceeding further.
Task<string> t1 = Task<string>.Factory.StartNew(() => LookUp1(lookUpObj));
Task<string> t2 = Task<string>.Factory.StartNew(() => LookUp2(lookUpObj));
Task<string> t3 = Task<string>.Factory.StartNew(() => LookUp3(lookUpObj));
Task<string> t4 = Task<string>.Factory.StartNew(() => LookUp4(lookUpObj));
Task<string> t5 = Task<string>.Factory.StartNew(() => LookUp5(lookUpObj));
Task.WaitAll(t1, t2, t3, t4, t5);
I have put in some log statements to confirm if these methods are getting called in parallel or not. First 4 methods are getting called in parallel with a time diff of around 100 milli seconds but the last one (5th one) method is invoked after a complete 1 second compared to others. I have given invoke time example in comments above.
Please let me know what I am doing wrong or is there any limitation on number of parallel calls or suggest any way to achieve this. Thanks in advance.
Thanks,
Akash Kansal.
What I have tried:
Parallel.Invoke(() => { r1 = Iteration1LookUp(lookUpObj); },
() => { r2 = Iteration2LookUp(lookUpObj); },
() => { r3 = Iteration3LookUp(lookUpObj); },
() => { r4 = Iteration4LookUp1(lookUpObj); },
() => { r5 = Iteration4LookUp2(lookUpObj); });
Tried this, but same kind of result.